CoreData 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.'

后端 未结 9 504
终归单人心
终归单人心 2020-12-24 02:58

I have been following these instructions to help integrate iCloud support with CoreData and I am getting some errors.

I have this in my AppDelegate:

         


        
9条回答
  •  [愿得一人]
    2020-12-24 03:22

    For me, I found addPersistentStoreWithType always returns nil in my case. So the persistent store wasn't created successfully. Then, I print the storeURL

    ~/Library/Developer/CoreSimulator/Devices/1F8C6299-1F80-4212-9FE2-CA33BD365851/data/Containers/Data/Application/9CA7B7BB-A835-4BC2-B12D-23B84D420F91/Library/Documentation/my-database.sqlite
    

    This is a directory in which we can't write data. So I checked my code and found a silly mistake.

    • I should use NSDocumentDirectory instead of NSDocumentationDirectory. Code completion in Xcode offers the documentation directory before the document directory enum.

    • When I used NSDocumentationDirectory, NSPersistentStoreCoordinator always tried to create the persist store in .../Library/Documentation/my-database.sqlite, which is an invalid path.

    • Instead, the correct path should be .../Documents/BeeLocation.sqlite.

提交回复
热议问题