@@ -13,9 +13,9 @@ extension CoreData.NSRelationshipDescription {
13
13
extension CoreData . NSRelationshipDescription : SchemaProperty { }
14
14
15
15
public extension CoreData . NSRelationshipDescription {
16
-
16
+
17
17
@inlinable var isToOneRelationship : Bool { !isToMany }
18
-
18
+
19
19
@inlinable var isAttribute : Bool { return false }
20
20
@inlinable var isRelationship : Bool { return true }
21
21
@@ -109,7 +109,7 @@ extension CoreData.NSRelationshipDescription {
109
109
// MARK: - Initializer
110
110
111
111
public extension CoreData . NSRelationshipDescription {
112
-
112
+
113
113
// Note: This matches what the `Relationship` macro takes.
114
114
convenience init ( _ options: Option ... , deleteRule: NSDeleteRule = . nullify,
115
115
minimumModelCount: Int ? = 0 , maximumModelCount: Int ? = 0 ,
@@ -122,16 +122,16 @@ public extension CoreData.NSRelationshipDescription {
122
122
precondition ( minimumModelCount ?? 0 >= 0 )
123
123
precondition ( maximumModelCount ?? 0 >= 0 )
124
124
self . init ( )
125
-
125
+
126
126
self . name = name ?? " "
127
127
self . valueType = valueType
128
128
self . renamingIdentifier = originalName ?? " "
129
129
self . versionHashModifier = hashModifier
130
130
self . deleteRule = deleteRule
131
131
self . inverseKeyPath = inverse
132
-
132
+
133
133
if options. contains ( . unique) { isUnique = true }
134
-
134
+
135
135
if let minimumModelCount { self . minCount = minimumModelCount }
136
136
if let maximumModelCount {
137
137
self . maxCount = maximumModelCount
@@ -140,7 +140,7 @@ public extension CoreData.NSRelationshipDescription {
140
140
if valueType is any RelationshipCollection . Type {
141
141
self . maxCount = 0
142
142
}
143
- else if valueType is NSOrderedSet . Type ||
143
+ else if valueType is NSOrderedSet . Type ||
144
144
valueType is Optional < NSOrderedSet > . Type
145
145
{
146
146
self . maxCount = 0
@@ -155,10 +155,8 @@ public extension CoreData.NSRelationshipDescription {
155
155
156
156
// MARK: - Storage
157
157
158
- private var _relationshipInfoAssociatedKey : UInt8 = 72
159
-
160
158
extension CoreData . NSRelationshipDescription {
161
-
159
+
162
160
func internalCopy( ) -> Self {
163
161
guard let copy = self . copy ( ) as? Self else {
164
162
fatalError ( " Could not copy relationship \( self ) " )
@@ -187,7 +185,7 @@ extension CoreData.NSRelationshipDescription {
187
185
var inverseName : String ?
188
186
var destination : String ?
189
187
var isToOneRelationship : Bool ?
190
-
188
+
191
189
override func copy( ) -> Any { internalCopy ( ) }
192
190
193
191
func internalCopy( ) -> MacroInfo {
@@ -201,11 +199,18 @@ extension CoreData.NSRelationshipDescription {
201
199
return copy
202
200
}
203
201
}
204
-
202
+
203
+ private struct AssociatedKeys {
204
+ #if swift(>=5.10)
205
+ nonisolated ( unsafe) static var relationshipInfoAssociatedKey : Void ? = nil
206
+ #else // 5.9: nonisolated(unsafe) not available
207
+ static var relationshipInfoAssociatedKey : Void ? = nil
208
+ #endif
209
+ }
210
+
205
211
var writableRelationshipInfo : MacroInfo {
206
- if let info =
207
- objc_getAssociatedObject ( self , & _relationshipInfoAssociatedKey)
208
- as? MacroInfo
212
+ if let info = objc_getAssociatedObject (
213
+ self , & AssociatedKeys. relationshipInfoAssociatedKey) as? MacroInfo
209
214
{
210
215
return info
211
216
}
@@ -214,16 +219,19 @@ extension CoreData.NSRelationshipDescription {
214
219
self . relationshipInfo = info
215
220
return info
216
221
}
217
-
222
+
218
223
var relationshipInfo : MacroInfo ? {
219
224
// Note: isUnique is only used during schema construction!
220
225
set {
221
- objc_setAssociatedObject ( self , & _relationshipInfoAssociatedKey,
222
- newValue, . OBJC_ASSOCIATION_RETAIN)
226
+ objc_setAssociatedObject (
227
+ self , & AssociatedKeys. relationshipInfoAssociatedKey,
228
+ newValue, . OBJC_ASSOCIATION_RETAIN
229
+ )
223
230
}
224
231
get {
225
- objc_getAssociatedObject ( self , & _relationshipInfoAssociatedKey)
226
- as? MacroInfo
232
+ objc_getAssociatedObject (
233
+ self , & AssociatedKeys. relationshipInfoAssociatedKey
234
+ ) as? MacroInfo
227
235
}
228
236
}
229
237
}
0 commit comments