Forming 'UnsafeRawPointer' to a variable of type 'Type'; this is likely incorrect because 'Type' may contain an object reference.
This largely rears its head when bridging to C or Obj-C APIs. However, it's rather unclear what the intended resolution for the warning should be without fundamentally changing what the code does (and the PR doesn't help). For example, in Obj-C, it's typical to use a string as an associated object key.
extension ObjCType {
private struct Keys { static var someKey = "someKey" }
var isSomeBool: Bool {
get { objc_getAssociatedObject(self, &Keys.someKey) as? Bool ?? false }
set {
objc_setAssociatedObject(self, &Keys.someKey, newValue, .OBJC_ASSOCIATION_COPY)
}
}
}
In this case it's possible to change the key type to something simple, like Bool, but that doesn't help if you're operating within an existing codebase and need compatibility with old code or SDKs. How would I keep compatibility here?
There are also examples where the underlying reference is actually important to the functionality of the code. For example, this OrderedSet comparison optimization from the Composable Architecture: