gpt4 book ai didi

swift - AppDelegate 类型的值在 swift 4 中没有成员 managedObjectContext

转载 作者:可可西里 更新时间:2023-11-01 01:56:50 27 4
gpt4 key购买 nike

我有代码:

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

但是xcode报错:

Value of type AppDelegate has no member managedObjectContext.

我想找到一个解决方案,非常感谢。

最佳答案

请使用下面的代码

import CoreData frame work
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

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

return true
}

关于swift - AppDelegate 类型的值在 swift 4 中没有成员 managedObjectContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52257314/

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