File tree Expand file tree Collapse file tree 2 files changed +66
-1
lines changed
Sources/StateStructMacros
Tests/StateStructMacroTests Expand file tree Collapse file tree 2 files changed +66
-1
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,19 @@ enum KnownTypes {
105105 ]
106106
107107 static func isPrimitiveType( _ typeName: String ) -> Bool {
108- primitiveTypes. contains ( typeName)
108+
109+ if typeName. hasSuffix ( " ? " ) {
110+ let unwrappedTypeName = typeName. replacingOccurrences ( of: " ? " , with: " " )
111+ return isPrimitiveType ( unwrappedTypeName)
112+ }
113+
114+ if typeName. hasPrefix ( " Optional< " ) && typeName. hasSuffix ( " > " ) {
115+ let unwrappedTypeName = typeName
116+ . replacingOccurrences ( of: " Optional< " , with: " " )
117+ . replacingOccurrences ( of: " > " , with: " " )
118+ return isPrimitiveType ( unwrappedTypeName)
119+ }
120+
121+ return primitiveTypes. contains ( typeName)
109122 }
110123}
Original file line number Diff line number Diff line change @@ -15,6 +15,58 @@ final class TrackingMacroTests: XCTestCase {
1515 }
1616 }
1717
18+ func test_primitive( ) {
19+
20+ assertMacro {
21+ """
22+ @Tracking
23+ struct MyState {
24+
25+ var int: Int
26+
27+ var int_literalOptional: Int?
28+
29+ var int_literalOptional_literalOptional: Int??
30+
31+ var int_typedOptinal: Optional<Int>
32+
33+ var int_typedOptional_typedOptional: Optional<Optional<Int>>
34+
35+ var int_typedOptional_literalOptional: Optional<Int?>
36+ }
37+ """
38+ } expansion: {
39+ """
40+ struct MyState {
41+ @PrimitiveTrackingProperty
42+
43+ var int: Int
44+ @PrimitiveTrackingProperty
45+
46+ var int_literalOptional: Int?
47+ @PrimitiveTrackingProperty
48+
49+ var int_literalOptional_literalOptional: Int??
50+ @PrimitiveTrackingProperty
51+
52+ var int_typedOptinal: Optional<Int>
53+ @PrimitiveTrackingProperty
54+
55+ var int_typedOptional_typedOptional: Optional<Optional<Int>>
56+ @PrimitiveTrackingProperty
57+
58+ var int_typedOptional_literalOptional: Optional<Int?>
59+
60+ internal var _tracking_context: _TrackingContext = .init()
61+ }
62+
63+ extension MyState: TrackingObject {
64+ }
65+ """
66+ }
67+
68+ }
69+
1870 func test_array_dictionary( ) {
1971 assertMacro {
2072 """
You can’t perform that action at this time.
0 commit comments