I've modified Apple's Lister sample to work with UIManagedDocument
instead of UIDocument
. Everything works except for deleting a document. When I attempt to delete a document using Apple's code in the removeListAtURL
method in ListUtilites.swift which uses the NSFileCoordinator
I get this error message after the listed document disappears then reappears in the simulator:
CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/.../AppGroup/E16FD6E8-8AD6-44BB-A031-5FB497F04FD4/Documents/myList.list/StoreContent/persistentStore options:{
NSPersistentStoreRemoveStoreOnCleanupKey = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134080 "(null)" UserInfo={NSUnderlyingException=Can't add the same store twice} with userInfo dictionary {
NSUnderlyingException = "Can't add the same store twice";
The "Can't add the same store twice" error doesn't make any sense to me since I'm deleting the file. Perhaps I need to close the file first? The file is local and not in iCloud so I don't think I need to delete any transaction logs. Also when I remove the NSFileCoordinator
code it works fine just user NSFileManager
right away it works fine for local files but I get the same error for iCloud files.
I forgot to close the document first. Remember kids, always close your documents before deleting them... especially UIManagedDocument
s.