Post

Replies

Boosts

Views

Activity

Reply to WidgetKit and CoreData/CloudKit
I don’t think this last comment is accurate, at least as of iOS 15. In digital lounges at WWDC Apple engineers explained it is possible for NSPersistentCloudKitContainer to sync while your app is open in the background. It seems though the work is scheduled with utility priority. In my testing it will sync if you make 4 changes - once enough updates are accumulated it’ll process them. But even then my widget is showing the changes from the 3rd update because it hasn’t yet finished updating it seems, and attempting to delay it causes the code not to execute I assume because iOS suspends the app again very soon after. So basically it may eventually sync in background, only if your app is already open in background, and it may not be reliable and your widget might not get the most up-to-date data. Maybe this can be improved by utilizing background task API, that’s what they suggested trying in the digital lounge. Do note they also said NSPersistentCloudKitContainer does not support multi-process sync so only your app should be attempting to sync. And even if a widget were to attempt sync, it’ll never really be able to because iOS doesn’t give it enough time to execute, and widgets don’t run in the background they’re only running when they need to get more timeline entries for example, and widgets don’t get the app’s push notifications which is what enables background syncs to be scheduled. Your app will need to try to keep the widget up to date as opposed to the widget attempting to sync and keep itself up to date.
Topic: App & System Services SubTopic: iCloud Tags:
Jun ’22
Reply to Color swatches in SwiftUI picker?
For Mac Catalyst I found this works well: Picker(selection: $selectedColorOption, label: Text("Color")) {     HStack {         Image(uiImage: colorSwatchImage(with: .red))         Text("Red")     }.tag(1) } .pickerStyle(.menu) private func colorSwatchImage(color: UIColor) -> UIImage {     let size = CGSize(width: 24, height: 12)     let rect = CGRect(origin: .zero, size: size)     let renderer = UIGraphicsImageRenderer(bounds: rect)     return renderer.image(actions: { context in         color.setFill()         UIBezierPath(roundedRect: rect, cornerRadius: 2).fill()     }) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’22
Reply to WidgetKit and CoreData/CloudKit
I don’t think this last comment is accurate, at least as of iOS 15. In digital lounges at WWDC Apple engineers explained it is possible for NSPersistentCloudKitContainer to sync while your app is open in the background. It seems though the work is scheduled with utility priority. In my testing it will sync if you make 4 changes - once enough updates are accumulated it’ll process them. But even then my widget is showing the changes from the 3rd update because it hasn’t yet finished updating it seems, and attempting to delay it causes the code not to execute I assume because iOS suspends the app again very soon after. So basically it may eventually sync in background, only if your app is already open in background, and it may not be reliable and your widget might not get the most up-to-date data. Maybe this can be improved by utilizing background task API, that’s what they suggested trying in the digital lounge. Do note they also said NSPersistentCloudKitContainer does not support multi-process sync so only your app should be attempting to sync. And even if a widget were to attempt sync, it’ll never really be able to because iOS doesn’t give it enough time to execute, and widgets don’t run in the background they’re only running when they need to get more timeline entries for example, and widgets don’t get the app’s push notifications which is what enables background syncs to be scheduled. Your app will need to try to keep the widget up to date as opposed to the widget attempting to sync and keep itself up to date.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Color swatches in SwiftUI picker?
For Mac Catalyst I found this works well: Picker(selection: $selectedColorOption, label: Text("Color")) {     HStack {         Image(uiImage: colorSwatchImage(with: .red))         Text("Red")     }.tag(1) } .pickerStyle(.menu) private func colorSwatchImage(color: UIColor) -> UIImage {     let size = CGSize(width: 24, height: 12)     let rect = CGRect(origin: .zero, size: size)     let renderer = UIGraphicsImageRenderer(bounds: rect)     return renderer.image(actions: { context in         color.setFill()         UIBezierPath(roundedRect: rect, cornerRadius: 2).fill()     }) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’22