Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to What are best practices for implementing data persistence on a watch only app?
This sounds like a good use case for Core Data, you can use it with any app architecture. CloudKit is not a solution for local persistence, it is basically a transport technology that you can use to store data in iCloud, synchronize data between a user's devices, or share content with other users. If you want your data to stay on the watch, NSPersistentContainer is your best option. If you want to sync data with your iOS app, use NSPersistentCloudKitContainer. The latter makes use of CloudKit to automatically mirror all local changes to iCloud and other devices.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’20
Reply to Specify Parent using NSPersistentCloudKitContainer
As of iOS 14, NSPersistentCloudKitContainer only supports the private database and the public database. If you want your users to be able to share data with others, you need to implement that code manually. Here's a great explanation of how sharing works along with some sample code: https://developer.apple.com/documentation/cloudkit/sharing_cloudkit_data_with_other_icloud_users If you want to share a certain object, you can ask NSPersistentCloudKitContainer for the underlying record using https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3141668-record. Initialize a new CKShare and set the record as its root record. Retrieve all other records for the hierarchy you'd like to share and set their parent property to the root record (not the share). Then you can save the CKShare using CKModifyRecordsOperation. Please refer to the documentation I've mentioned above to set up a CKDatabaseSubscription and fetch changes from the shared database as. they come in
Jun ’20
NSPersistentCloudKitContainer sharing with the new databaseScope option
I'm really excited about the new public database options introduced in the Sync a Core Data store with the CloudKit public database talk! I see in the documentation that the databaseScope refers to the CKDatabase.Scope which includes an option for the shared database. Does this mean that we will be able to automatically sync CoreData records to a shared CloudKit database this year? I would really like to add support to my app to sync data with friends through CloudKit, but with the existing system it is too much work to sync shared objects through a CKShare, so I have avoided building it so far. I'm really excited to start using the new changes. Thanks!
5
0
1.7k
Jun ’20
Reply to WidgetKit and CoreData/CloudKit
I might have answered my own question. First, add a managedObject variable to the TimelineProvider and a initializer: struct Provider: IntentTimelineProvider { var managedObjectContext : NSManagedObjectContext init(context : NSManagedObjectContext) { self.managedObjectContext = context } ... Then initialize the persistentContainer within the Widget struct and pass the persistentContainer.viewContext into the new Provider initializer: struct Widget_Extension: Widget { private let kind: String = Widget_Extension public var body: some WidgetConfiguration { IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider(context: persistentContainer.viewContext), placeholder: PlaceholderView()) { entry in Widget_ExtensionEntryView(entry: entry) } .configurationDisplayName(My Widget) .description(This is an example widget.) } var persistentContainer: NSPersistentCloudKitContainer = {... return container }() The Provider now has access to your CoreData+CloudKit data.
Jun ’20
Is it safe to use a NSPersistentCloudKitContainer on a Share Extension?
I have an app that uses NSPersistentCloudKitContainer to store all the data so it's backed by iCloud and synced between devices. Such app has a Share Extension, that can be triggered both from iOS (and iPadOS) and macOS (Catalyst). I was wondering if it's safe to instantiate an NSPersistentCloudKitContainer from a Share Extension due to it being very short lived. At the moment, I'm sending the data straight to iCloud instead of instantiating an NSPersistentCloudKitContainer, but it feels wrong because I'm using the keys that NSPersistentCloudKitContainer created internally (CD_MyEntity, CD_myProperty, etc.) to send it to iCloud and then being correctly pulled by my clients. The only concern that I have is that bringing up an NSPersistentCloudKitContainer that has to pull data, might delay or even loose the data that I'm saving right now because it gets killed after some amount of time since the share action has been completed. Any insights will be much appreciated,
3
0
2.1k
Jun ’20
Persistent Storage for Previewing
In the previous version of my app, I used this pattern for previews that depended on a NSManagedObjectContext: struct ContentView_Previews: PreviewProvider { static var previews: some View { tttt let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext return ContentView().environment(.managedObjectContext, managedObjectContext) } } With the delegate gone, I've swapped to this: class PreviewData { static var persistentContainer: NSPersistentContainer = { let container = NSPersistentCloudKitContainer(name: Structure) container.loadPersistentStores(completionHandler: { _, error in if let error = error { fatalError(Unresolved error (error)) } }) return container }() static var previewContext: NSManagedObjectContext { persistentContainer.viewContext } This works for previews some of the time. For example, I have this FilteredList: import CoreData import SwiftUI protocol StructureManagedObject { static var defaultSortDescriptors: [NSSortDescriptor] { get }
3
0
1.7k
Jun ’20
Reply to Using Core Data with SwiftUI App Protocol
@micho2, to achieve CloudKit integration you should be able to change the persistentContainer property like so... var persistentContainer: NSPersistentContainer = { ttttlet container = NSPersistentCloudKitContainer(name: SampleApp) tttttt // change this line container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { ttttttttfatalError(Unresolved error (error), (error.userInfo)) } }) ttttcontainer.viewContext.automaticallyMergesChangesFromParent = truetttttttt // add this line return container }() although I've not tested this yet!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’20
Reply to Getting Started With Core Data SwiftUI XCode12
This thread provides an example of a SwiftUI + Core Data setup: https://developer.apple.com/forums/thread/650876 To clarify some terms: Core Data is a framework for local persistence and CloudKit can be seen as a transport technology that deals with storing data in iCloud. If you want to store objects from Core Data in iCloud, you can implement the syncing behavior on your own or make use of NSPersistentCloudKitContainer, a class that automatically mirrors changes in a local Core Data container to iCloud and keeps each device up-to-date.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’20
A suggestion for another way to implement public database syncing
In session wwdc20-10650 - https://developer.apple.com/videos/play/wwdc2020/10650/ Sync a Core Data store with the CloudKit public database at 14:22, Nick says NSPersistentCloudKitContainer can't use CKFetchRecordZoneChangesOperation with the public database, it has to use CKQueryOperation. I was wondering why didn't you use CKSubscription? Create a subscription for each record type and the CKQueryNotification can contain CKQueryNotificationReasonRecordDeleted. It's been a while since I worked on my own public database sync but I think that is how I did it. This is the second time I've heard of the sync design being affected by limitations of CloudKit and it worries me. The first time it was when you decided not to use CKReference and instead create your own relation records because you said CloudKit had a limit on the number of references. Personally I didn't think the number was too low and I didn't understand why it couldn't just be raised, and if you had paired that with the non-public CKReference
1
0
915
Jun ’20