@@ -48,7 +48,38 @@ private let toManyRelationshipTypes : Set<String> = [
48
48
]
49
49
50
50
extension TypeSyntax {
51
+
52
+ /// Whether the type can be represented in Objective-C.
53
+ /// A *very* basic implementation.
54
+ var canBeRepresentedInObjectiveC : Bool {
55
+ // TODO: Naive shortcut
56
+ if let id = self . as ( IdentifierTypeSyntax . self) {
57
+ return id. isKnownAttributePropertyType
58
+ || id. isKnownRelationshipPropertyType
59
+ }
60
+
61
+ if let opt = self . as ( OptionalTypeSyntax . self) {
62
+ if let id = opt. wrappedType. as ( IdentifierTypeSyntax . self) {
63
+ return id. isKnownAttributePropertyType
64
+ || id. isKnownRelationshipPropertyType
65
+ }
66
+ // E.g. this is not representable: `String??`, this is `String?`.
67
+ // I.e. nesting of Optional's are not representable.
68
+ return false
69
+ }
70
+ if let array = self . as ( ArrayTypeSyntax . self) {
71
+ // This *is* representable: `[String]`,
72
+ // even this `[ [ 10, 20 ], [ 30, 40 ] ]`
73
+ return array. element. canBeRepresentedInObjectiveC
74
+ }
75
+
76
+ return false
77
+ }
51
78
79
+ /**
80
+ * This checks for some known basetypes, like `Int`, `String` or `Data`.
81
+ * It also unwraps optionals, arrays and such.
82
+ */
52
83
var isKnownAttributePropertyType : Bool {
53
84
if let id = self . as ( IdentifierTypeSyntax . self) {
54
85
return id. isKnownAttributePropertyType
0 commit comments