0

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.

HangarRash
  • 7,314
  • 5
  • 5
  • 32
presto
  • 1
  • The fact that this occurs in 14.2 but not 16 suggests it's an Apple bug that has been fixed. Does it reproduce on iOS 16 at all? – Rob Napier Mar 13 '23 at 18:16
  • hmm.. actually it is also vague. some teammates said they can reproduce the issue on iOS 16.2 devices. – presto Mar 14 '23 at 06:09

0 Answers0