Post

Replies

Boosts

Views

Activity

Reply to How to get notified on CKError.quotaExceeded
Thank you for your reply. I have tried something like the following, however the "quotaExceeded" never gets printed even though the above error message does. I can see also that the code enters the .partialFailure section of the if, however ckerror.partialErrorsByItemID is always nil or an empty list. Any suggests on how to unpack the error and get to the underlying .quotaExceeded? class SyncMonitor { /// Where we store Combine cancellables for publishers we're listening to, e.g. NSPersistentCloudKitContainer's notifications. fileprivate var disposables = Set<AnyCancellable>() init() { NotificationCenter.default.publisher(for: NSPersistentCloudKitContainer.eventChangedNotification) .sink(receiveValue: { notification in print("notification: \(notification)") if let cloudEvent = notification.userInfo?[NSPersistentCloudKitContainer.eventNotificationUserInfoKey] as? NSPersistentCloudKitContainer.Event { // NSPersistentCloudKitContainer sends a notification when an event starts, and another when it // ends. If it has an endDate, it means the event finished. if cloudEvent.endDate == nil { print("Starting an event...") // You could check the type, but I'm trying to keep this brief. } else { switch cloudEvent.type { case .setup: print("Setup finished!") case .import: print("An import finished!") case .export: print("An export finished!") @unknown default: assertionFailure("NSPersistentCloudKitContainer added a new event type.") } if cloudEvent.succeeded { print("And it succeeded!") } else { print("But it failed!") } if let error = cloudEvent.error { print("Error: \(error.localizedDescription)") guard let ckerror = error as? CKError else { return } print("Error: code: \(ckerror.code), \(ckerror.localizedDescription)") if ckerror.code == .partialFailure { guard let errors = ckerror.partialErrorsByItemID else { return } for (_, error) in errors { if let currentError = error as? CKError { print(currentError.localizedDescription) } } } else if ckerror.code == .quotaExceeded { print("quotaExceeded") } } } } }) .store(in: &disposables) } }
Jan ’24
Reply to How do you make a button respond to an external keyboard key press?
I probably should have provided example code. Suppose I have a SwiftUI View like this:struct MyView: View { var body: some View { Button(action: { print("A") }) { Text("A") } Button(action: { print("B") }) { Text("B") } } }This accepts touches on A and B presented on the screen and causes the associated action closures to run. How would I accept an external physical keyboard press of A or B to cause the code in the closures to run?
Feb ’20