Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

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
Persisting a PKDrawing to iCloud
I have an App in which I am using NSPersistentCloudKitContainer to store user's drawings, and to have them in sync across multiple devices. To store the drawings, I am using a Binary Data attribute in my Core Data entity. In this attribute I am saving the data representation of the drawing by using this API https://developer.apple.com/documentation/pencilkit/pkdrawing/3281878-datarepresentation I have observed that for some drawings this data representation consumes a huge amount of data, and that generates synchronisation problems among devices. Is there a better approach to persist PKDrawings without this problem?
2
0
1.2k
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
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 Check Data Re-Sync on App Reinstall with CloudKit (+SwiftUI)
I'm using an almost identical CoreData stack as to what was shown in the WWDC 2019 Posts demo app. Here's the code: import Foundation import CoreData // MARK: - Core Data Stack /** The main Core Data stack setup including history processing./ class CoreDataStack { tt/** ttttA persistent container that can load cloud-backed and non-cloud stores. tt */ ttlazy var persistentContainer: NSPersistentCloudKitContainer = { tttt tttt// Create a container that can load CloudKit-based stores ttttlet container = NSPersistentCloudKitContainer(name: MyCoreDataApp) tttt tttt// Enable history tracking and remote notifications ttttguard let description = container.persistentStoreDescriptions.first else { ttttttfatalError(###(#function): Failed to retrieve a persistent store description.) tttt} ttttdescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) ttttdescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) tttt ttttcontainer.loadPer
Jun ’20
Reply to NSPersistentCloudKitContainer and CloudKit for Sharing
Yes, NSPersistentCloudKitContainer doesn't support sharing, you have to implemented that code manually. Here's a great walkthrough along with some sample code: https://developer.apple.com/documentation/cloudkit/sharing_cloudkit_data_with_other_icloud_users You can obtain an NSManagedObject's underlying CKRecord using https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3141668-record Basically, you need to create a CKShare for each record you'd like to share. Don't forget to setup a CKDatabaseSubscription to get notified about changes. After changing the record, receivers of the share need to store it back to the shared database (and not to their private database, unless they're the owner of the record).
Jun ’20
Where's the documented record method for NSPersistentCloudKitContainer?
I would need to access CKRecords of my NSManagedObjects on iOS 13.4 and there seems to be a documented method in NSPersistentCloudKitContainer, but the compiler can't see it! How this can be?Compilation error:https://vesacdn.s3.eu-north-1.amazonaws.com/compilation+error.pngClass definition seen by xcode 11.4.1:https://vesacdn.s3.eu-north-1.amazonaws.com/NSPersistentCloudKitContainer.pngDocumented:https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer
1
0
527
Jun ’20
Reply to CloudKit + CoreData: Now how do I take advantage of CloudKit user-to-user sharing without losing CoreData + CloudKit synchronization?
You can use NSPersistentCloudKitContainer, but you have to implement the code for sharing manually. Here's a great description of what's needed along with sample code: https://developer.apple.com/documentation/cloudkit/sharing_cloudkit_data_with_other_icloud_users You can retrieve CKRecord objects from NSPersistentCloudKitContainer using https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3141668-recordformanagedobjectid?language=objc
Jun ’20