请求更新,因为此问题当然已针对先前版本得到解答,最新的搜索结果日期为12月16日与之前的iOS 9和10项目产生无关的兼容性.
文档当然是说在开始一个新项目时选择使用核心数据复选框,我没有选择,但现在认为需要添加iCloud核心数据以使我的应用程序进入下一阶段 – >其中需要NSFileCoordinator和NSFilePresenter之类的东西,因为在我的应用UI中,用户会看到一些TOPICS,每个都有三个OPTIONS,用户可以选择一个选项.对于每个主题,UI然后显示已选择每个选项的总用户数和每个选项的总计PERCENTAGE.
现在,每个选项的选择数量和总数的百分比当然只是在我的原生应用程序中计算的 – >但实际上需要在像云一样的中心或者很可能在网站上进行计算…但是网站引发了NSFileCoordinator和NSFilePresenter已经解决的同时读/写问题.
因此,如果iCloud核心数据系统可以插入现有的泛在容器数值总计的基本算术计算 – 在接收来自各个用户的写入数值命令时在云中 – 在发出新的无处不在的容器数值总和和百分比值之前 – 那么我’非常感谢建议在尝试创建和初始化核心数据堆栈时如何修复下面生成的错误.否则猜测我将不得不刮掉Xcode并转到像PhoneGap这样的混合应用程序,如果这是最好的工作.
因此,请参阅核心数据编程指南:
Use of unresolved identifier ‘persistentContainer’… ‘managedObjectContext’
……错误.和线
init(completionClosure: @escaping () -> ()) {
…生成
Initializers may only be declared within a type
import UIKit import CoreData class DataController: NSObject { var managedObjectContext: NSManagedObjectContext init(completionClosure: @escaping () -> ()) { persistentContainer = NSPersistentContainer(name: "DataModel") persistentContainer.loadPersistentStores() { (description,error) in if let error = error { fatalError("Failed to load Core Data stack: \(error)") } completionClosure() } } } init(completionClosure: @escaping () -> ()) { //This resource is the same name as your xcdatamodeld contained in your project guard let modelURL = Bundle.main.url(forResource: "DataModel",withExtension:"momd") else { fatalError("Error loading model from bundle") } // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model. guard let mom = NSManagedObjectModel(contentsOf: modelURL) else { fatalError("Error initializing mom from: \(modelURL)") } let psc = NSPersistentStoreCoordinator(managedObjectModel: mom) managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.mainQueueConcurrencyType) managedObjectContext.persistentStoreCoordinator = psc let queue = DispatchQueue.global(qos: DispatchQoS.QoSClass.background) queue.async { guard let docURL = FileManager.default.urls(for: .documentDirectory,in: .userDomainMask).last else { fatalError("Unable to resolve document directory") } let storeURL = docURL.appendingPathComponent("DataModel.sqlite") do { try psc.addPersistentStore(ofType: NSsqliteStoreType,configurationName: nil,at: storeURL,options: nil) //The callback block is expected to complete the User Interface and therefore should be presented back on the main queue so that the user interface does not need to be concerned with which queue this call is coming from. DispatchQueue.main.sync(execute: completionClosure) } catch { fatalError("Error migrating store: \(error)") } } } // followed by my existing working code: class ViewController: UIViewController {