Post

Replies

Boosts

Views

Activity

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
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 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 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 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 Fetch data from WatchOS CoreData for WatchOS 9 widget with an App Group
I worked out why I've been getting this error with the Widget, I was trying to fetch directly from PersistenceController() eg. let myfetchedContactCards = try persistenceController().shared.managedObjectContext.fetch(fetchRequest) but when I changed to let persistenceController = PersistenceController.shared let myfetchedContactCards = try persistenceController.managedObjectContext.fetch(fetchRequest) It worked. Must have fully loaded the model. I was trying to access before it had loaded?
Sep ’22
Reply to Can't Load Image on Apple Watch Complications with New iOS 16 Widget
Resize the image to width of 50 using this extension extension UIImage { func resized(toWidth width: CGFloat? = 50.0, isOpaque: Bool = true) -> UIImage { let canvas = CGSize(width: width ?? 50.0, height: CGFloat(ceil((width ?? 50.0)/size.width * size.height))) let format = imageRendererFormat format.opaque = isOpaque return UIGraphicsImageRenderer(size: canvas, format: format).image { _ in draw(in: CGRect(origin: .zero, size: canvas)) } } } to use UIImage.resized then the widget should load
Sep ’22
Reply to Privacy redaction not working in iOS16 beta widget
I am having a lot of trouble with this. My idea was going to be to put a switch in the setting page of my app so user can choose if they want sensitive information redacted or not. Some people may want to hide their appointment on the Lock Screen, others may not. redacted(reason: .placeholder) works fine. but the .privacy reason docent seam to work. If I add the capability to the target 'Data Protection' every thing on the widget gets redacted, unless I mark elements with .unredacted() But to have to do that for everything is too difficult. My thinking around how it worked was to add the modifier, redacted(reason: .privacy) to an element like a Text view or an image and if the device is locked that will be redacted. I must not have the same thinking as Apple on this process.
Sep ’22