Questions tagged [nspersistentcontainer]

25 questions
23
votes
1 answer

Failed to find a unique match for an NSEntityDescription CoreData Swiftui

When I use my app, sometimes, I have an error that appear, it seems to be randomly (or I didn't figure out when exactly...), then all my lists are empty (like if nothing were in CoreData). But If I close my app and re-open it, lists appear without…
Clément Tengip
  • 618
  • 6
  • 19
10
votes
2 answers

ViewContext not receiving updates from newBackgroundContext()

There is a similar question in stack overflow already but it doesn't work for me. There is a use case in my application where I have to observe the database changes to perform some operation. To receive updates I subscribed to …
5
votes
0 answers

How to Migrate Core Data's Data to App Group's Data

I just added App Groups to my app using this StackOverFlow post. Unfortunately since the defaultDirectoryURL is changing, I can not fetch any of the old data I made before using the App Groups directory. I know the data is still there because when I…
ap123
  • 916
  • 1
  • 8
  • 22
4
votes
0 answers

When using NSPersistentCloudKitContainer: what to do if the user logs out of iCloud?

From several Apple WWDC talks on CloudKit, when using CloudKit to sync private user data across devices, when the user logs out of iCloud, the App is supposed to empty the on-device cache / local replica (I use Core Data for on-device permanence).…
3
votes
0 answers

Core Data on Rare Occasions Randomly Deletes Everything

Very rarely (<1% of users), a user will inform me that they open my app, and all their data is gone. The problem I'm having is that I am unable to replicate the issue because it happens so rarely. I don't even know how to begin fixing this problem.…
Arturo Lee
  • 61
  • 1
  • 8
3
votes
0 answers

NSPersistentContainer & NSFetchedResultsController with large data set

We recently switched our app over to using NSPersistentContainer to set up our Core Data stack. The removal of boilerplate such as automatic consuming of save notifications and merge handling was appealing to us, plus it's supposed to be set up to…
John Rogers
  • 2,192
  • 19
  • 29
3
votes
0 answers

NSPersistentContainer Lightweight Migrations in Core Data iOS10 +

I have added a new data model. Added a few new attributes to an Entity. Told xCode to use the new version. Am I right in thinking that if using NSPersistentContainer, that's all I have to do and xCode will automatically perform the lightweight…
RyanTCB
  • 7,400
  • 5
  • 42
  • 62
2
votes
1 answer

CoreData & CloudKit toggle iCloud sync (enable/disable)

Since my last question (here toggle between local and iCloud CoreData store) I was able to make a lot of progress. I am switching between NSPersistentCloudKitContainer and NSPersistenttContainer But... When I switch off the CloudKit synchronization…
2
votes
1 answer

Why data is removed if I enable light-weight migration in swift 5?

I have successfully launched 1st version of my App with MyProject.xcdatamodel. Now my 2nd version is under development and I created new model version named MyProject2.xcdatamodel based on MyProject.xcdatamodel and set it to Current. I have enabled…
2
votes
1 answer

Core data: Trouble with using environment variable managedObjectContext

I'm new to swift and I have trouble with understanding how environment variables works. In Core Data, I created new Entity called "API" with one attribute id: Int32. Then in SwiftUI, I wanted to find maximum value of id. I wrote a request, but…
1
vote
1 answer

How can I connect a context to a persistent store coordinator in a sheet?

App description I am creating a swiftUI app (called Interval) that uses CoreData to store Workouts and their Steps in a one-to-many relationship. Each Workout has many Steps. View hierarchy ContentView -> DetailView -> EditView (as a…
1
vote
1 answer

CoreData - load local and AppGroup NSPersistentContainers

I want to load both the local's NSPersistentContainer and the AppGroup's NSPersistentContainer Here is what I did : class MyAppGroupPersistentContainer: NSPersistentContainer{ override class func defaultDirectoryURL() -> URL{ return…
1
vote
0 answers

Using 2 NSPersistentContainer

Is it possible to have multiple NSPersistentContainer hooked up to the same store in a project. Im changing an existing implementation which uses 2 NSPersistentStoreCoordinator to use NSPersistentContainer.
1
vote
1 answer

How do I create a variable for NSPersistentContainer and NSPersistentCloudKitContainer with the same name but set depending on the version?

I cannot change my exciting core data stack to NSPersistentCloudKitContainer because that is only a iOS 13 and later support feature but would like to have that set for iOS 13 and later while having NSPersistentContainer for earlier versions. I have…
117MasterChief96
  • 548
  • 1
  • 5
  • 16
1
vote
0 answers

Core Data load persistent store using AppGroups

I need to access persistent container in my main target as well as app extension. So I have created a framework to share code and I created a NSPersistentContainer subclass like this : class PersistentContainer: NSPersistentContainer { override…
Reckoner
  • 1,041
  • 2
  • 13
  • 29
1
2