gpt4 book ai didi

swift - 错误 : Trying to put the stack in unreadable memory at:

转载 作者:搜寻专家 更新时间:2023-10-30 21:56:37 42 4
gpt4 key购买 nike

我正在尝试向 UIViewController 添加其他属性。

代码:

protocol AdditionalStoredProperties
{
associatedtype Title
func getAssociatedObject<Title>(key: UnsafePointer<Title> ,
defValue : Title)->Title
}

extension AdditionalStoredProperties
{
func getAssociatedObject<Title>( key: UnsafePointer<Title> , defValue : Title)->Title
{
guard let actual_value = objc_getAssociatedObject(self as! AnyObject, key) as? Title else
{
return defValue
}
return actual_value
}

}

extension UIViewController:AdditionalStoredProperties
{
typealias Title = String
var previousPage : String
{
get { return getAssociatedObject(&self.previousPage, defValue: self.previousPage) }
set { objc_setAssociatedObject(self, &self.previousPage, newValue, .OBJC_ASSOCIATION_RETAIN)}
}
}

但是我收到以下错误:

错误:试图将堆栈放入不可读的内存中:

我知道我们不能直接将存储的属性添加到扩展中,所以我尝试使用 objc_setAssociatedObject() 添加

最佳答案

如果有人遇到以下情况

If your method is getting called recursively, you may get this error.

关于swift - 错误 : Trying to put the stack in unreadable memory at:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45541575/

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