大佬教程收集整理的这篇文章主要介绍了如何将Core Data添加到现有的Xcode 9 Swift 4 iOS 11项目中?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
文档当然是说在开始一个新项目时选择使用核心数据复选框,我没有选择,但现在认为需要添加iCloud核心数据以使我的应用程序进入下一阶段 – >其中需要NSFileCoordinator和NSFilePresenter之类的东西,因为在我的应用UI中,用户会看到一些TOPICS,每个都有三个OPTIONS,用户可以选择一个选项.对于每个主题,UI然后显示已选择每个选项的总用户数和每个选项的总计PERCENTAGE.
现在,每个选项的选择数量和总数的百分比当然只是在我的原生应用程序中计算的 – >但实际上需要在像云一样的中心或者很可能在网站上进行计算…但是网站引发了NSFileCoordinator和NSFilePresenter已经解决的同时读/写问题.
因此,如果iCloud核心数据系统可以插入现有的泛在容器数值总计的基本算术计算 – 在接收来自各个用户的写入数值命令时在云中 – 在发出新的无处不在的容器数值总和和百分比值之前 – 那么我’非常感谢建议在尝试创建和初始化核心数据堆栈时如何修复下面生成的错误.否则猜测我将不得不刮掉Xcode并转到像PhoneGap这样的混合应用程序,如果这是最好的工作.
因此,请参阅核心数据编程指南:
……错误.和线
init(completionClosure: @escaping () -> ()) {
…生成
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 {
以上是大佬教程为你收集整理的如何将Core Data添加到现有的Xcode 9 Swift 4 iOS 11项目中?全部内容,希望文章能够帮你解决如何将Core Data添加到现有的Xcode 9 Swift 4 iOS 11项目中?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。