Skip to content

Commit e2899ae

Browse files
committed
Add @objc to members that we know can be represented in ObjC
Partially addresses issue #36. This works for hardcoded base types, some Foundation types and if the property is explicitly tagged as a Relationship.
1 parent 38886e0 commit e2899ae

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Sources/ManagedModelMacros/ModelMacro/ModelMemberAttributes.swift

+17-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ extension ModelMacro: MemberAttributeMacro { // @attached(memberAttribute)
2929
return [] // TBD: rather throw?
3030
}
3131

32+
// This is an array because the `member` declaration can contain multiple
33+
// bindings, e.g.: `var street, city, country : String`.
34+
// Those are NOT all the properties of the `declaration` (e.g. the class).
3235
var properties = [ ModelProperty ]()
3336
addModelProperties(in: member, to: &properties,
3437
context: context)
@@ -41,7 +44,20 @@ extension ModelMacro: MemberAttributeMacro { // @attached(memberAttribute)
4144
}
4245

4346
guard !property.isTransient else { return [] }
47+
48+
/*
49+
// property.declaredValueType is nil, but we detect some
50+
var firstname = "Jason"
51+
// property.declaredValueType is set
52+
var lastname : String
53+
*/
54+
let addAtObjC = property.isKnownRelationshipPropertyType
55+
|| (property.valueType?.canBeRepresentedInObjectiveC ?? false)
4456

45-
return [ "@_PersistedProperty" ]
57+
// We'd like @objc, but we don't know which ones to attach it to?
58+
// https://github.com/Data-swift/ManagedModels/issues/36
59+
return addAtObjC
60+
? [ "@_PersistedProperty", "@objc" ]
61+
: [ "@_PersistedProperty" ]
4662
}
4763
}

0 commit comments

Comments
 (0)