In Objective-C, I might use +[NSValue valueWithNonretainedObject:]
to keep a unique ID of an object, where I don't wish to retain the object itself. Seems like that's deprecated for Swift.
How to do in Swift?
In Objective-C, I might use +[NSValue valueWithNonretainedObject:]
to keep a unique ID of an object, where I don't wish to retain the object itself. Seems like that's deprecated for Swift.
How to do in Swift?
It's still there. It's just been adjusted to be one of NSValue
's initializers:
let anObject = "Hello!"
let value = NSValue(nonretainedObject: anObject)
This works:
let foo: NSString = "hello"
let fooval: NSValue = NSValue(nonretainedObject: foo)
fooval.description // evaluates to "<5040d191 b87f0000>", address of `foo`