有没有办法实现这个功能?
解决方法 我的经验最好的解决方案是拥有多个托管对象上下文,每个都有自己的模型.但是,有一种方法来完成你想要的:
// create the store coordinatorNSPersistentStoreCoordinator *storeCoordinator = [[NSPersistentStoreCoordinator alloc] init];// create the first storeNSPersistentStore *firstStore = [storeCoordinator addPersistentStoreWithType: NSIncrementalStore configuration:nil URL:urlToFirstStore options:optionsForFirstStore error:&error];// Now create the second oneNSPersistentStore *secondStore = [storeCoordinator addPersistentStoreWithType:NSsqliteStore configuration:nil URL:urlToSecondStore options:optionsForSecondStore error:&error];// Now you have two stores and one contextNSManagedobjectContext *context = [[NSManagedobjectContext alloc] init];[context setPersistentStoreCoordinator:storeCoordinator];// and you can assign your entitIEs to different stores like thisNSManagedobject *someObject = [[NSManagedobject alloc] initWithEntity:someEntity insertIntoManagedobjectContext:context];// here the relevant part[context assignObject:someObject topersistentStore:firstStore]; // or secondStore ..
您还应检查这些链接,以更好地了解Core Data的工作原理:
Core Data Programming Guide – Persistent Store Coordinator
SO: Two persistent stores for one managed object context – possible?
SO: Can two managed object context share one single persistent store coordinator?
还要查看TechZen在关于配置的第二个链接中的评论,并在这里阅读:
Core Data Programming Guide – Configurations
这里是一个很好的教程来管理两个对象上下文:
Multiple Managed Object Contexts with Core Data
总结以上是内存溢出为你收集整理的ios – NSPersistentStoreCoordinator有两种类型的持久存储?全部内容,希望文章能够帮你解决ios – NSPersistentStoreCoordinator有两种类型的持久存储?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)