Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to Access Core App Data from IOS widget
I wanted to give this thread a bump because I too am facing the same issue. The proposed answer from rr0924, and the referenced article from Antoine van der Lee, does not work for me either. To inject my CoreData model into the Widget extension one failing attempt I've tried was to use a similar method in my iOS app and watchOS companion app. For example this code will allow proper access to CoreData from iOS and watchOS; @main struct RunRosterApp: App { @Environment(.scenePhase) private var scenePhase @StateObject private var persistentStore = PersistentStore.shared var body: some Scene { WindowGroup { ContentView() .environment(.managedObjectContext, persistentStore.context) } } The PersistentStore class is a set up as a singleton to load the NSPersistentCloudKitContainer. That code is fairly boiler plate so I won't post it but can upon request. Using a similar pattern in WidgetKit and SwiftUI I currently have this; @main struct WidgetRunPlanner: Widget { @StateObject private var persistentStore =
Topic: App & System Services SubTopic: General Tags:
Aug ’20
Reply to NSCloudKitMirroringExportRequest issues
I'll make a guess you are implementing your App struct as if it were a class and accidentally creating a new instance of NSPersistentCloudKitContainer every time SwiftUI recreates the struct. You could access the persistent container lazy property through a @UIApplicationDelegateDelegateAdaptor so it is only created once. import SwiftUI import CoreData @main struct MasterDetailApp: App { t@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate tt ttvar body: some Scene { ttttWindowGroup { ttttttContentView().environment(.managedObjectContext, appDelegate.persistentContainer.viewContext) tttt} tt} }
Aug ’20
NSPersistentCloudKitContainer stops syncing
I have moved my NSPersistentContainer in my app to an NSPersistentCloudKitContainer to sync data between devices (iPhone, iPad, and Apple Watch supported). Sync works just fine in test & production, but after a few days it will stop working and behave as if each device is using local storage. This continues to happen until I reinstall the app and it syncs again, but only for a short time until it goes back to using local storage again. Does anyone know of a way to debug this?
3
0
882
Jul ’20
Reply to CloudKit + CoreData: Now how do I take advantage of CloudKit user-to-user sharing without losing CoreData + CloudKit synchronization?
I've tried to implement some code for sharing manually with working CloudKit + CoreData mirroring. I've stuck on the parent records (I have one-to-many relationship and child records need to be shared when parent record is shared) and here is why. I've implemented code that is setting parent records for each NSManagedObject's CKRecord, syncing works well, but it causes huge troubles like: I call my setParentRecords among other places from NWPathMonitor's pathUpdateHandler (literally when internet restored), and fetching NSManagedObjects that's CKRecords if any don't have parent on the server yet. Apple's NSCloudKitMirroringDelegate is doing the same also on internet restore. And my any fetching at this second causes crash of Mirroring. Mirroring do not work since this point and says probably no internet each time! I could not beat that problem and I am afraid that will have to implement whole sync by myself, even for privateDatabase just because of such bugs (and no any completion handlers in NSPersistentCloudKitContainer
Jul ’20
Reply to CoreData in Swift Packages
Hi, This post helped me so I figured I'd post a working example of the core data model that I am successfully using in a new Swift Package. This code below is from the lazy var persistentContainer: let bundle = Bundle.module let modelURL = bundle.url(forResource: ModelName, withExtension: .momd)! let model = NSManagedObjectModel(contentsOf: modelURL)! let container = NSPersistentCloudKitContainer(name: ModelName, managedObjectModel: model) You can make the model a lazy var. I call it from the host app below: NavigationLink(destination: GenericListCDView() .environment(.managedObjectContext,ModelCDStack.shared.context) , label: { Text(My List) }) Hope this helps.
Jul ’20
NSPersistentCloudKitContainer: Set To-One relation to nil is not synced to CloudKit
Using NSPersistentCloudKitContainer: I have a relation between Item --to-one--> Group. This works fine on device: I can set a Group for an Item and remove the Item from the Group again, everything is persisted locally. The Problem: Adding does work, but removing the Group never appears on a different device. As soon as the Item gets edited on the different device, the Group relation re-appears with the new changes (even if manually removed there as well). What I see in CloudKit dashboard: Group field on Item is of type String. A fresh Item record, never assigned to a Group, does not have the Group field. Removing the Group does not remove the Group field in CloudKit. As soon as it gets a Group field, I can’t get rid of it. Manually emptying the value causes to crash on download. Reproducible with the example project: The behaviour can easily be reproduced with the example project (https://developer.apple.com/documentation/coredata/synchronizing_a_local_store_to_the_cloud?language=objc). Just repla
6
0
1.2k
Jul ’20
CloudKit integration seeding, conflicted objects log
Hello,I have an issue in an app which is yet unreleased.The app uses Core Data, and I recently added CloudKit integration.Whenever I start the app data get automatically downloaded by CloudKit and I get this log: <NSCloudKitMirroringDelegate: 0x600001da61b0> - Never successfully initialized and cannot execute request '<NSCloudKitMirroringImportRequest: 0x6000024c88a0> D3FB21AB-94ED-40B7-859B-6CBEE6149473' due to error: Error Domain=NSCocoaErrorDomain Code=134404 (null) UserInfo={NSDetailedErrors=( Error Domain=NSCocoaErrorDomain Code=133021 (null) UserInfo={NSExceptionOmitCallstacks=true, conflictList=(n NSConstraintConflict (0x600003f40e00) for constraint (n namen): database: 0x8143748c0004e8e1 <x-coredata://272191BB-7D10-41DD-8E4B-56F4ECE4AB9F/Ingredient/p195>, conflictedObjects: (n 0x8143748c181ce8e1 <x-coredata://272191BB-7D10-41DD-8E4B-56F4ECE4AB9F/Ingredient/p1733>n),n NSConstraintConflict (0x600003f42fc0) for constraint (n namen): database: 0x8143748c029ce8e1 <x-coredata://27
3
0
1.3k
Jul ’20
Reply to CloudKit + CoreData: Now how do I take advantage of CloudKit user-to-user sharing without losing CoreData + CloudKit synchronization?
Yes, It is not supported and you can use it, but have to write some extra code can be read as either saying the same thing, or contradicting each other, and after spending some hours looking through forums and documentation, without more context your intended meaning of NSPersistentCloudKitContainer does not yet support sharing isn't obvious to me. Contributing to my confusion, about a year ago the answer given included - https://developer.apple.com/forums/thread/117938?answerId=376835022#376835022: NSPersistentCloudKitContainer does not support sharing.... and As others have (correctly) pointed out, NSPersistentCloudKitContainer maintains a specific zone in the private database, and therefore will never see any shared zones owned by other users. Three weeks ago this answer - https://developer.apple.com/forums/thread/651651?answerId=616641022#616641022 also seems to say no: NSPersistentCloudKitContainer only supports the private database and the public database. If you wan
Jul ’20
Reply to CloudKit + CoreData: Now how do I take advantage of CloudKit user-to-user sharing without losing CoreData + CloudKit synchronization?
I'm not sure how to rectify the two answers from Apple. The staff answer reads to me as yes, with some extra work. The engineer answer reads to me as a flat no, don't even try. Can someone please clarify? Does does not yet support sharing mean you literally can't use sharing with NSPersistentCloudKitContainer at all, even with additional code?
Jul ’20
Reply to Error while trying to save two records with CKReference to each other
Ok I've narrowed the issue down. If my call to setParent on the Chat object (line 13 above of the first code listing). If I remove this line. Everything works and my two references are saved so each record has a reference to each other. However I believe then that I'm missing the benefits of using setParent? So that when I do an update to a child object things are kept in sync? Or is setParent only to be used when using CoreData/CloudKit syncing that was introduced in 2019 with NSPersistentCloudKitContainer? I'm not using that (as much as I'd like to) because I need to share my records. So I'm doing the Core Data/Cloud Kit syncing myself.
Jul ’20
Core Data + Cloudkit not synching
I have a Core Data + Couldkit App where any changes made on other device is not synched. I had to call the fetch method again refresh the data. I even added the necessary lines, let container = NSPersistentCloudKitContainer(name: myappcontainername) container.viewContext.automaticallyMergesChangesFromParent = true The following are the CoreData logs after making a change, CoreData+CloudKit: -[NSCloudKitMirroringDelegate finishedAutomatedRequestWithResult:](2119): Finished request '<NSCloudKitMirroringExportRequest: 0x6> -UUID' with result: <NSCloudKitMirroringResult: 0x> success: 1 madeChanges: 1 error: (null) What else should I be doing to make this work?
1
0
679
Jul ’20