János János - 4 years ago 293
iOS Question

How to add object to an NSPointerArray?

I want to store weak references in an

but I get an error:

public var objectWithReloadFRC = NSPointerArray(options: NSPointerFunctionsWeakMemory)
objectWithReloadFRC.addPointer(self) //self is an UIViewController subclass

enter image description here

tried this too:


Answer Source

You can get a pointer to the storage used for an object with unsafeAddressOf(). Since addPointer() requires a mutable pointer, another conversion is needed:


Swift 3:

var objectWithReloadFRC = NSPointerArray(options: .weakMemory)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download