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.
It's still there. It's just been adjusted to be one of NSValue's initializers:
let anObject = "Hello!"
let value = NSValue(nonretainedObject: anObject)
3
votes
This works:
let foo: NSString = "hello"
let fooval: NSValue = NSValue(nonretainedObject: foo)
fooval.description // evaluates to "<5040d191 b87f0000>", address of `foo`
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more