nspersistentstore

Core Data. How to swap NSPersistentStores and inform NSFetchedResultsController?

ぃ、小莉子 提交于 2020-01-11 07:50:13
问题 I'm implementing backup and restore (via Dropbox) of a user's Core Data persisted data. For a restore I pull the files down from Dropbox and store them temporarily in the Documents directory. Then I create a new NSPersistentContainer and use it to replace the current persistent store (in the ApplicationSupport directory) before deleting the no longer needed files in the Documents directory. I'm using the MasterDetail template for now and so I have the usual time-stamped entities and the

Referring to NSPersistentStore instances created in AppDelegate

丶灬走出姿态 提交于 2019-12-25 04:27:07
问题 I modified the boilerplate core data stack code you get with a core data application to add two NSPersistentStore s to the NSPersistentStoreCoordinator instead of just one. // MARK: - Core Data stack lazy var applicationDocumentsDirectory: NSURL = { let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) return urls[urls.count-1] as NSURL }() lazy var managedObjectModel: NSManagedObjectModel = { let modelURL = NSBundle.mainBundle()

Remove Core Data from iCloud fails

风流意气都作罢 提交于 2019-12-22 13:56:22
问题 I'm trying to remove Core Data from iCloud using [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:] . But I get strange output: __93+[NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:]_block_invoke(1982): CoreData: Ubiquity: Unable to move content directory to new location: file:///private/var/mobile/Library/Mobile%20Documents/<UBIQUITY_ID>/ New: file:///private/var/mobile/Library/Mobile%20Documents

Refresh NSPersistentStoreCoordinator in AppDelegate from ViewController

戏子无情 提交于 2019-12-13 07:36:05
问题 I have an app where the PersistentStoreCoordinator is set up within AppDelegate. I want to load a new sqlite database from a list of saved sqlite files. I'm happy with deleting the existing Persistent Store and sqlite file and replacing the sqlite file with the one loaded from the table. However, how do I reload/refresh the PersistentStoreCoordinator from the ViewController action of selecting the new file? I've tried setting AppDelegate as a delegate of the ViewController, but this seems to

NSPersistentStoreCoordinator throws EXC_BAD_ACCESS when deallocating an NSManagedObject after reading a specific NSManagedProperty

假装没事ソ 提交于 2019-12-12 20:03:16
问题 Error Description I have an app with some data stored locally using core data (backed by SQLite) and the following NSManagedObject subclass import CoreData @objc(ScoutingEventData) class ScoutingEventData: NSManagedObject { @NSManaged var id: String? @NSManaged var type: String? @NSManaged var entityId: String? @NSManaged var oldStateJson: NSData? @NSManaged var newStateJson: NSData? @NSManaged var eventDate: NSDate? func toInsertEvent() throws -> ScoutingEvent.Insert { guard let id = id else

How to create sharable Core Data .sqlite backups locally and in iCloud using current NSPersistentStore methods

夙愿已清 提交于 2019-12-11 07:31:56
问题 I have been having quite a time of figuring out the correct way to create a backup of a Core-Data backed .sqlite file and storing that backup, both locally and/or in iCloud (whatever the user prefers), for download, restore or sharing. Let me state up front that I am not talking about moving the persistent store to iCloud to be used by the app as its datasource. I am simply asking about creating backup files in this question. In 2014, Apple changed their default journaling mode for Core Data

New project New Model NSPersistentDocument This NSPersistentStoreCoordinator has no persistent stores

▼魔方 西西 提交于 2019-12-11 05:45:54
问题 I have been searching stackoverflow and Googling for hours. I made a simple project to mess around with Core Data and bindings. It added an entity to the model and it wouldn't work any more. I was getting "This NSPersistentStoreCoordinator has no persistent stores It cannot perform a save operation" whenever I tried to add data to a new document. I followed every piece of advice I could find with no luck. Finally, I made a new project (NSPersistentDocument based) and I made a new model from

Pre load core data database coming up black with UIManagedDocument

本小妞迷上赌 提交于 2019-12-08 07:44:57
问题 Hi supportive experts... I'm writing my first iPad app and have a working beta copy that parses an XML file to create a UIManagedDocument Core Data DB on app start up. However this takes a long time and I would like to do it once off line and include the initial data directly into my app bundle. Needless to say I'm hitting a wall trying to get it to work. I first followed the command line utility approach see here This worked until I imported the .sqlite file and tried to edit the

Is NSInMemoryStoreType Incompatible with NSBatchDeleteRequest?

只谈情不闲聊 提交于 2019-12-08 05:00:43
问题 I am currently unit testing a layer that interacts with Core Data. It saves, deletes, and updates an Item object. However, my test that attempts to save a couple of Item s and then perform a batch deletion keeps failing. This is Item : extension Item { // MARK: - Properties @NSManaged public var date: NSDate @NSManaged public var isTaxable: Bool @NSManaged public var name: String @NSManaged public var price: NSDecimalNumber @NSManaged public var quantity: Double // MARK: - Fetch Requests

Remove Core Data from iCloud fails

你。 提交于 2019-12-06 08:28:38
I'm trying to remove Core Data from iCloud using [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:] . But I get strange output: __93+[NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:]_block_invoke(1982): CoreData: Ubiquity: Unable to move content directory to new location: file:///private/var/mobile/Library/Mobile%20Documents/<UBIQUITY_ID>/ New: file:///private/var/mobile/Library/Mobile%20Documents/OldUbiquitousContent-mobile~C9439AD0-1E87-4977-9C68-0674F5E2E93B Error Domain=NSCocoaErrorDomain Code=513 "The