gpt4 book ai didi

ios - 如何将对象添加到 NSPointerArray?

转载 作者:可可西里 更新时间:2023-11-01 00:23:48 25 4
gpt4 key购买 nike

我想在 NSPointerArray 中存储弱引用,但出现错误:

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

enter image description here

也试过这个:

objectWithReloadFRC.addPointer(UnsafePointer(self)

最佳答案

您可以获得指向用于对象的存储的指针unsafeAddressOf()。由于 addPointer() 需要一个可变指针,需要另一个转换:

objectWithReloadFRC.addPointer(UnsafeMutablePointer(unsafeAddressOf(self)))

swift 3:

var objectWithReloadFRC = NSPointerArray(options: .weakMemory)
objectWithReloadFRC.addPointer(Unmanaged.passUnretained(self).toOpaque())

关于ios - 如何将对象添加到 NSPointerArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31191067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com