Search results for

“NSPersistentCloudKitContainer”

601 results found

Post

Replies

Boosts

Views

Activity

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
532
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
Reply to NSPersistentCloudKitContainer not syncing data on macOS
You can use the feedback assistant to file bugs against NSPersistentCloudKitContainer. Include the following: A sysdiagnose from all of the participating devices The persistent store files from all of the participating devices If your dataset is large, a detailed accounting of the affected records and the mutations made to them from each device (as well as you recall, history tracking is the truth)
Jun ’20
Reply to Core Data and SwiftUI in Xcode 12
You need to create a custom Core Data class and inject it into ContentView() I don‘t have a default file at hand but you can inject it like below let context = PersistentCloudKitContainer.persistentContainer.viewContext tt ContentView().environment(.managedObjectContext, context) Below my CloudKitContainer but you can simply change that to a regular PersistentContainer class import CoreData public class PersistentCloudKitContainer { tt tt// MARK: - Define Constants / Variables ttpublic static var context: NSManagedObjectContext { ttttreturn persistentContainer.viewContext tt} tt tt// MARK: - Initializer ttprivate init() {} tt tt// MARK: - Core Data stack ttpublic static var persistentContainer: NSPersistentCloudKitContainer = { tt ttttlet container = NSPersistentCloudKitContainer(name: Container_Name) ttttcontainer.loadPersistentStores(completionHandler: { (storeDescription, error) in ttttttif let error = error as NSError? { ttttttt ttttttttfatalError(Unresolved error (error), (error.userInf
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’20
Reply to Using iCloud Integration for Core Data with SwiftUI App Protocol
You can use this approach https://developer.apple.com/forums/thread/650876 and then use the NSPersistentCloudKitContainer instead of NSPersistentContainer. A good explanation of how to integrate the NSPersistentCloudKitContainer properly is here: andrewcbancroft.com/blog/ios-development/data-persistence/getting-started-with-nspersistentcloudkitcontainer/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’20
Reply to Core Data shared persistent container partial mirror
When you're using NSPersistentCloudKitContainer for the public database, all public data will be replicated to your users' devices. For your use case, it's probably best to not use NSPersistentCloudKitContainer for the public database and operate on it using the regular CloudKit operations.
Replies
Boosts
Views
Activity
Jun ’20
Reply to Migration of local core data to iCloud core data
You can use NSPersistentCloudKitContainer and point it to the same storage file that you were using before so your users won't lose any data. Please keep in mind that all your data doesn't get uploaded right away, only objects that have changed after migrating to NSPersistentCloudKitContainer are being uploaded.
Replies
Boosts
Views
Activity
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
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Jun ’20
Delete all data from CloudKit using NSPersistentCloudKitContainer
What is the recommended approach to allowing a user to delete all the data they have in their Core Data store plus all the data mirrored to CloudKit via NSPersistentCloudKitContainer? How would such a technique work with multiple devices?
Replies
1
Boosts
0
Views
1.6k
Activity
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
Replies
Boosts
Views
Activity
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).
Replies
Boosts
Views
Activity
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
Replies
1
Boosts
0
Views
532
Activity
Jun ’20
Reply to Check Data Re-Sync on App Reinstall with CloudKit (+SwiftUI)
The data should still be stored in iCloud and NSPersistentCloudKitContainer should take care of downloading data that is in CloudKit. Could you please post the setup of your Core Data stack?
Replies
Boosts
Views
Activity
Jun ’20
Reply to How to fix ZONE_NOT_FOUND error in CloudKit Dashboard?
I think this is expected. NSPersistentCloudKitContainer saves data to CloudKit and it encounters this error the first time it saves something to the cloud. It automatically creates the zone and it won't encounter this error on subsequent requests. That's why you're only seeing this error once per user.
Replies
Boosts
Views
Activity
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
Replies
Boosts
Views
Activity
Jun ’20
Reply to NSPersistentCloudKitContainer not syncing data on macOS
You can use the feedback assistant to file bugs against NSPersistentCloudKitContainer. Include the following: A sysdiagnose from all of the participating devices The persistent store files from all of the participating devices If your dataset is large, a detailed accounting of the affected records and the mutations made to them from each device (as well as you recall, history tracking is the truth)
Replies
Boosts
Views
Activity
Jun ’20
Reply to Core Data and SwiftUI in Xcode 12
You need to create a custom Core Data class and inject it into ContentView() I don‘t have a default file at hand but you can inject it like below let context = PersistentCloudKitContainer.persistentContainer.viewContext tt ContentView().environment(.managedObjectContext, context) Below my CloudKitContainer but you can simply change that to a regular PersistentContainer class import CoreData public class PersistentCloudKitContainer { tt tt// MARK: - Define Constants / Variables ttpublic static var context: NSManagedObjectContext { ttttreturn persistentContainer.viewContext tt} tt tt// MARK: - Initializer ttprivate init() {} tt tt// MARK: - Core Data stack ttpublic static var persistentContainer: NSPersistentCloudKitContainer = { tt ttttlet container = NSPersistentCloudKitContainer(name: Container_Name) ttttcontainer.loadPersistentStores(completionHandler: { (storeDescription, error) in ttttttif let error = error as NSError? { ttttttt ttttttttfatalError(Unresolved error (error), (error.userInf
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’20
NSPersistentCloudKitContainer and Sharing in iOS 14
I see some sessions about using NSPersistentCloudKitContainer with the public CloudKit database, and it now accepts a ‘databaseScope’ property - can this be used with shared CloudKit databases?
Replies
1
Boosts
0
Views
725
Activity
Jun ’20