Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

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
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 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
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
Why? "CloudKit integration does not support unique constraints"
Hi, On iOS 14 beta 1-3 I was happily using a constraint on several entities in NSPersistentCloudKitContainer. The part of the app using this was essentially an RSS reader - two different devices were independently fetching news and no duplicates due to the constraints. Now on iOS14 beta 4 I'm receiving CloudKit integration does not support unique constraints, which means I've had to remove the constraints.. Now the app is subject to CloudKit sync vs RSS import timing issues.. if CloudKit syncs after the RSS import then there are duplicate items. What's the workaround for this please? It really should just work. Thanks, Andy
6
0
4.6k
Aug ’20
[NSPersistentCloudKitContainer][Mac Catalyst specific crash] app is constantly crashing within a minute or two
Core Data, Catalyst, CloudKIt engineers need your assistance. I have an app that uses NSPersistentCloudKitContainer. It works great on iOS, but on the mac (Catalyst), the app is constantly crashing and is unusable. The CloudKit scheduler com.apple.xpc.activity.com.apple.cloudkit.scheduler.com.apple.coredata.cloudkit.activity.export seems to be at fault. It's crashing inside a generic dispatch block, so it's impossible to debug. Found a similar thread: https://developer.apple.com/forums/thread/128131?page=1 This is on Catalina 10.15.5 (19F101). MacBook Pro (Retina, 13-inch, Early 2015) Any ideas on how to debug/solve the root cause of this issue? Here's the image of the crash report (image hosted on imgbb.com): ibb.co nQy6rwm Thread 19 Queue : com.apple.xpc.activity.com.apple.cloudkit.scheduler.com.apple.coredata.cloudkit.activity.export (serial) #0 0x00007fff73de0436 in __xpcactivitydispatchblockinvoke.109.cold.3 () #1 0x00007fff73dde82b in _xpcactivitydispatchblockinvoke.109 () #2 0x000000010040f844
1
0
925
Aug ’20
Reply to NSSecureUnarchiveFromData is now necessary for transformable attributes but does not work with Core Data CloudKit?
I was able to remove the warnings by registering a new value transformer. I'm persisting a CLLocation, which conforms to NSSecureCoding. import Foundation import CoreLocation @objc(CLLocationValueTransformer) final class CLLocationValueTransformer: NSSecureUnarchiveFromDataTransformer { static let name = NSValueTransformerName(rawValue: String(describing: CLLocationValueTransformer.self)) override static var allowedTopLevelClasses: [AnyClass] { return [CLLocation.self] } public static func register() { let transformer = CLLocationValueTransformer() ValueTransformer.setValueTransformer(transformer, forName: name) } } Adding CLLocationValueTransformer as the transformer name works without warnings. The value is synced properly via NSPersistentCloudKitContainer, verified on multiple devices.
Aug ’20
NSPersistentCloudKitContainer change cloudKitContainerOptions while app is running
I use NSPersistentCloudKitContainer to sync my apps data to iCloud. The app has a settings switch to enable or disable iCloud sync. As described in this thread, - https://developer.apple.com/forums/thread/118924 I set cloudKitContainerOptions to nil depending on the users setting. This is done before the persistent stores are loaded and works fine when the app is launched for the first time. My problem is that I don't know how to apply this settings change while NSPersistentCloudKitContainer is already loaded and active and its ManagedObjectContexts are in use? I could reload the entire container, but will that work while the app is still using contexts from the other container?
3
0
1.4k
Aug ’20
How to import data from iPhone system File to the app other than the app's iCloud at first through Share Extension?
The local data in iPhone system File is inserted to the app core data through Share Extension. The app uses NSPersistentCloudKitContainer to sync core data. But when importing local data from iPhone local File, the data always go to iCloud of the app at first and then syncing data to the app from iCloud. This leads to that the app cannot import data when the iCloud drive is closed or the iCloud is full. Is there any way to import data to the app other than to the app's iCloud at first?
0
0
871
Aug ’20
Reply to WidgetKit and CoreData/CloudKit
Hi cristosv, Thanks for posting your solution to this online. I'm having the same problem, but it would be great it for you could help a little more. For example, all your code is working fine, but I can't seem to figure out how to use my core data entity in a Text() view in my widget. Below is my code, and any help with this or more sample code would be great. Thanks 🙏 import WidgetKit import SwiftUI import Intents import CoreData struct Provider: IntentTimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), configuration: ConfigurationIntent()) } func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date(), configuration: configuration) completion(entry) } func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline) -> ()) { var entries: [SimpleEntry] = [] // Generate a timeline consisting of five entries an
Aug ’20