I wrote codes like below. this code is in static framework.
private struct AssociatedKeys {
static var someKey = "someKey"
}
extension SomeClass {
public var someProperty: String? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.someKey) as? String
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.someKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
someProperty
is defined with public
, so another framework can access to SomeClass.someProperty
.
but when another framework accesses to SomeClass.someProperty
, &AssociatedKeys.someKey
value in each get/set clause are different. So we cannot get valid someProperty
value. It always returns nil
.
this issue is not reproduced when the code is in dynamic framework. and it is reproduced on iOS 14.2 simulator, but not reproduced on iOS 16.0 simulator.
is this about UnsafeRawPointer
operation? anyone can help us?
when the property is not public
(ex. internal
, fileprivate
, private
), the associated keys were same. so it seems that it is reproduced when the property is opened.