Post

Replies

Boosts

Views

Activity

Reply to Making FetchRequest from CoreData in IntentHandler for WidgetKit
I could never figure out yet why I can't fetch from The intent file, the fetch error catch bit gets called because I put a dummy entry in there that would display on an error. the app group share file approach I put in the comments is the best solution I've found so far, and just an update, after deleting the Derived Data file from the Mac the widget is working on the Mac now so I'm happy with that.
Mar ’21
Reply to Making FetchRequest from CoreData in IntentHandler for WidgetKit
I have the same issue, I can not fetch from the IntentHandler.swift so in my App I created an array of values when the appp opens and closes that saves some values to an array in the app group, let defaults = UserDefaults.init(suiteName: "group.my-app")! defaults.setValue(CoreDataStack.createArrayOfContactsForWidget(), forKey: "ContactsForWidgetIntent") static func createArrayOfContactsForWidget() - [String] {         var arrayOfContactIDsAndNames = [String] ()         let fetchRequest = NSFetchRequestUser()         let entity = User.entity()         fetchRequest.entity = entity         fetchRequest.predicate = NSPredicate(format: "isVisible = %@", "1")         do {             var users = try CoreDataStack.managedObjectContext!.fetch(fetchRequest)             users.sort(by: { $0.first_name $1.first_name })             for user in users {                 //To get an array of currently added users                 arrayOfContactIDsAndNames.append("\(user.contactID)|\(Helper.getUserFullName(user: user))")             }         } catch {print(error)}         return arrayOfContactIDsAndNames     } Then in the intent I pull that contact ID and the name to display and it works fine on iPhone but not on Mac. ... contactIDsArray = defaults.value(forKey: "ContactsForWidgetIntent") as! [String]     for user in contactIDsArray {         let values = user.components(separatedBy: "|")         let contactID = values[0]         let name = values[1]         let personIntentObject = Person(identifier: "\(contactID)", display: "\(name)")         userItems.append(personIntentObject)     }     completion(INObjectCollection(items: userItems), nil) Not sure why but its working on iPhone. On Mac I get an error that there are No options provided for this parameter
Mar ’21
Reply to Widget SwiftUI previews failure when adding a dependency
I am creating a widget that has configurable content and I'm getting this error on the Mac OS when running the WidgetExtension in the Mac WidgetKit Simulator The operation could not be completed. (CHSErrorDomain error 1101.) I must be missing something somewhere, all my other widgets are working fine, but with the dynamic widget where the user can edit the widget in the swift file I'm always getting warnings that appear then disappear about Cannot find type 'DynamicPersonSelectionIntent' in scope When I build it goes away. I have added DynamicPersonSelection.intentdefinition, I have an IntentHandler.swift with an IntentHandler: DynamicPersonSelectionIntentHandling.in the Target Intent handler I have added the supported Intent, In the framework section is the Intents.framework. I have check all the Tagret memberships I think. The widget works sometimes? on the iPhone but not on the Mac at all. I must be missing something. Please help if you can.
Mar ’21
Reply to Core data Array and Conforming to NSSecureCoding
Hi, Thank you for the Swift reply. The example you provided proceeded with no error, which is a good thing and the phone numbers were stored and accessed, its working I think. Thank you. I changed the transformable type in the Core data to NSArray and allowedTopLevelClasses to return [CNLabeledValueCNPhoneNumber.self, NSArray.self, CNPhoneNumber.self] //- as you suggested and it worked. So thank you again. I am going to try now to do the same with CNLabeledValueNSString and a postal address, that should be similar. Thank you! I really appreciated your help.
Feb ’21
Reply to Update an Existing Xcode Project Core Data with CloudKit & Manage Multiple Stores
Hi, I think I found the answer let storeDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first! let url = storeDirectory.appendingPathComponent("local.sqlite") let local = NSPersistentStoreDescription(url: url) ... let cloudUrl = storeDirectory.appendingPathComponent("cloud.sqlite") let cloud = NSPersistentStoreDescription(url: cloudUrl) Something to do with the path as I thought. Changing those lines seams to have made it work.
Sep ’20