gpt4 book ai didi

swift - UIApplication.shared.delegate.persistentContainer.viewContext 为零?

转载 作者:行者123 更新时间:2023-11-28 15:43:26 24 4
gpt4 key购买 nike

我正在为我的应用程序添加核心数据。我使用的代码与我在具有完全相同架构的测试应用程序中使用的代码完全相同,但我得到了不同的结果。

var context: NSManagedObjectContext!
let appDelegate = UIApplication.shared.delegate as! AppDelegate
context = appDelegate.persistentContainer.viewContext

是我用来在我的 VC 中设置的代码,但在我的实际应用程序中此后上下文为 nil。此外,如果我使用调试器查看 appDelegate 内部,在我的大型应用程序中 persistentContainer.storage 为 nil,但在测试应用程序中我可以查看它的内部并查看 _viewContext 等 Prop 。我担心在执行将核心数据添加到已创建的应用程序的步骤时,我可能会错过一些东西。知道我的问题可能是什么吗?

最佳答案

检查 appDelegate 中 NSPersistentContainer 的名称。这可能会为您提供上下文的 nil 值

关于swift - UIApplication.shared.delegate.persistentContainer.viewContext 为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43421974/

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