You can gather type definitions from Swift source code.
let reader = Reader()
let source = """
struct S {
var a: Int?
}
"""
let result = try reader.read(source: source)
let s = try XCTUnwrap(result.types[safe: 0]?.struct)
XCTAssertEqual(s.name, "S")
XCTAssertEqual(s.storedProperties.count, 1)
let a = try XCTUnwrap(s.storedProperties[safe: 0])
XCTAssertEqual(a.name, "a")
let aType = try XCTUnwrap(a.type?.struct)
XCTAssertEqual(aType.name, "Optional")
XCTAssertEqual(aType.genericsArguments.count, 1)
let aWrappedType = try XCTUnwrap(aType.genericsArguments[safe: 0]?.struct)
XCTAssertEqual(aWrappedType.name, "Int")
This library doesn't distinguish type descriptor and concrete type. It make implementation simple but ugly especially when generic argument application happens.
class C {}
struct S {
var x: Int { 0 }
var y: Int {
get { _y }
set { _y = newValue }
}
var _y: Int = 0
}
struct S {
func f() {}
}
struct S {
var a = 0
}
struct S {
var f: () -> Void
}