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

标签 swift

我正在尝试向 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/

相关文章:

iOS UICircularProgressRing 径向渐变

objective-c - "Swift is build on top of C and Objective C without constraints of C compatibility"是什么意思?

ios - 重新加载 TableView 中除第一个单元格之外的所有行的最有效方法是什么?

swift - 打开文件对话框在 Swift 中崩溃

Swift - 未在表格 View 单元格中触发按钮操作

swift - swift toInt() 中的用户输入返回 nil

swift - 每月重置一个值 - swift 和 firebase

swift 。为什么 dataTaskWithRequest 不调用闭包?

ios - 如何在 Swift 中以编程方式设置 UITableView 单元格高度?

ios - 运行自定义 shell 脚本 '[cp] embed pods frameworks' 没有那个文件或目录