Swiftpack.co - omochi/SwiftTypeReader as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by omochi.
omochi/SwiftTypeReader 2.7.0
You can gather type definitions from Swift source code.
⭐️ 27
🕓 5 weeks ago
.package(url: "https://github.com/omochi/SwiftTypeReader.git", from: "2.7.0")


You can gather type definitions from Swift source code.


    func testReadmeExample() throws {
        try withExtendedLifetime(Context()) { (context) in
            let module = context.getOrCreateModule(name: "main")
            let reader = Reader(context: context, module: module)

            let source = try reader.read(
                source: """
struct S {
    var a: Int?
                file: URL(fileURLWithPath: "S.swift")
            _ = source

            let s = try XCTUnwrap(module.find(name: "S")?.asStruct)
            XCTAssertEqual(s.name, "S")

            XCTAssertEqual(s.storedProperties.count, 1)
            let a = try XCTUnwrap(s.find(name: "a")?.asVar)
            XCTAssertIdentical(a, s.storedProperties[safe: 0])
            XCTAssertEqual(a.name, "a")

            let aType = try XCTUnwrap(a.interfaceType.asEnum)
            XCTAssertEqual(aType.name, "Optional")
            XCTAssertEqual(aType.genericArgs.count, 1)

            let aWrappedType = try XCTUnwrap(aType.genericArgs[safe: 0]?.asStruct)
            XCTAssertEqual(aWrappedType.name, "Int")

More documents

Unsupported language features

Function body

It handles only signature.

Generic signatures of function

Variable without type annotation

struct S {
    var a = 0

It doesn't have type inference.


This library focus to use for building other libraries below.

But It's useful in standalone for other purpose like meta programming for Swift.


Design consideration

This library refer to the Swift compiler and Slava's book to build architecture. It provides decls, types, and type reprs.

Code generation

$ swift package codegen


Stars: 27
Last commit: 5 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

5 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics