Post

Replies

Boosts

Views

Activity

ContactAccessButton and contactAccessPicker in UIKit
Hi, I am looking at the ContactAccessButton and contactAccessPicker functionality that's new in iOS18. I had a couple of questions about this: is this available through UIKit as well as SwiftUI, or is it a SwiftUI-only feature? is it going to be available on the Mac as well as iOS? Thanks.
Topic: UI Frameworks SubTopic: General
2
1
812
Jun ’24
CloudKit user 'throttling'
Hi, I have some small amount of users who are receiving a lot of "throttling" error messages from CloudKit when they try to upload / download data from CloudKit. I can see this from the user reports as well as the CloudKit dashboard. It's erratic, unpredictable, and is causing all sorts of bad experience in my app. I would like to understand this more: what causes a particular user to 'throttle' vs others, and what can they do to avoid it? as an e.g if we are uploading 4000 records, having split them up into a 100 CKModifyRecordsOperations with 400 records each ... would that result in some operations getting 'throttled' in the middle of the upload? Would all the operations receive the 'throttled' error message, or only some operations? if I replay all the operations after the recommended timeout, could they also get a 'throttle' response? how do I reproduce something like this in the development environment? With my testing and development so far, I haven't run into such an issue myself. Would love to hear some insight and suggestions about how to handle this.
2
0
817
Jun ’24
Contacts: remove member from group not working on macOS
Hi, In my app, I have an option to remove a contact from a contact group (using the Contacts framework), and it's been working fine till recently users of the macOS version reported that it's not working. I have been using the CNSaveRequest removeMember(contact, from: group) API. The same API works fine on iOS. I'm not sure when it started but it seems to be affecting macOS14.6 as well as 15.1. I was able to reproduce it in a small test project as well, and have the same experience (the API works on iOS but not on macOS), so it definitely seems like a problem with the framework. Can someone confirm this, and/or suggest a workaround? Here's the code I run to test it out ...a simple SwiftUI view that has 4 buttons: Create contact and group Add contact to group Remove contact from group (optional) cleanup by deleting contact and group It's the 3rd step that seems to fail on macOS, but works fine on iOS. Here's the code to test it out: struct ContentView: View { let contactsModel = ContactsStoreModel() var body: some View { VStack (alignment: .center, spacing: 15){ Button ("1. Add Contact And Group") { print("add contact button pressed") contactsModel.addTestContact() if let _ = contactsModel.createdContact { print("created contact success") } } Button ("2. Add Contact To Group") { print("add to group button pressed") contactsModel.addContactToGroup() } Button ("3. Remove Contact From Group") { print("remove from group button pressed") contactsModel.removeContactFromGroup() } Button ("4. Delete Contact and Group") { print("remove from group button pressed") contactsModel.deleteContactAndGroup() } } .padding() } } #Preview { ContentView() } @available(iOS 13.0, *) @objc final class ContactsStoreModel: NSObject, ObservableObject { let contactStore = CNContactStore() var createdContact : CNContact? var createdGroup : CNGroup? public func addTestContact() { let storeContainer = contactStore.defaultContainerIdentifier() let contact = CNMutableContact() contact.givenName = "Testing" contact.familyName = "User" contact.phoneNumbers = [CNLabeledValue(label: "Cell", value: CNPhoneNumber(stringValue: "1234567890"))] let group = CNMutableGroup() group.name = "Testing Group" print("create contact id = \(contact.identifier)") print("create group id = \(group.identifier)") do { let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.add(contact, toContainerWithIdentifier: storeContainer) saveRequest.add(group, toContainerWithIdentifier: storeContainer) try contactStore.execute(saveRequest) createdContact = contact createdGroup = group } catch { print("error in store execute = \(error)") } } public func addContactToGroup() { if let contact = createdContact, let group = createdGroup { do { let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.addMember(contact, to: group) try contactStore.execute(saveRequest) } catch { print("error in store execute = \(error)") } } } public func removeContactFromGroup() { if let contact = createdContact, let group = createdGroup { do { let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.removeMember(contact, from: group) try contactStore.execute(saveRequest) } catch { print("error in store execute = \(error)") } } } public func addGroupAndContact() { let storeContainer = contactStore.defaultContainerIdentifier() let group = CNMutableGroup() group.name = "Test Group" print("create group id = \(group.identifier)") if let contact = createdContact { do { let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.add(group, toContainerWithIdentifier: storeContainer) saveRequest.addMember(contact, to: group) try contactStore.execute(saveRequest) createdGroup = group } catch { print("error in store execute = \(error)") } } } public func deleteContactAndGroup() { if let contact = createdContact, let group = createdGroup { do { let mutableGroup = group.mutableCopy() as! CNMutableGroup let mutableContact = contact.mutableCopy() as! CNMutableContact let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.delete(mutableContact) saveRequest.delete(mutableGroup) try contactStore.execute(saveRequest) } catch { print("error in deleting store execute = \(error)") } } } }
2
0
567
Dec ’24
SwiftUI: TextField not getting focus changes inside Button
I have a SwiftUI List (on macOS) where I want to display a few TextFields in each row, and observe how the focus changes as an individual text field is selected or unselected. This seems to work fine if I just have the List display a pure TextField in each row, but if I embed the TextField inside a Button view, the focus change notifications stop working. I want the 'button' functionality so that the user can tap anywhere on the row and have the text field activated, instead of tapping exactly on the text field boundary. Here is some code to demonstrate the problem. In the List if you have RowView uncommented out (1), then the focus change notifications work. If you comment that out and uncomment the RowViewWithButton (2), then the button functionality works, but I can't get focus change notifications anymore. Here is the code to reproduce the issue. Interestingly, when I test this on iOS, it works fine in both cases. But I need the solution for macOS. import SwiftUI // test on macOS target struct ContentView: View { @State private var textFields = Array(repeating: "", count: 4) @FocusState private var focusedField: Int? var body: some View { List(0..<4, id: \.self) { index in // 1. works with focus notification changes RowView(index: index, text: $textFields[index], focusedField: $focusedField) // 2. button works, but no focus notifications on text field //RowViewWithButton(index: index, text: $textFields[index], focusedField: $focusedField) } } } struct RowView: View { let index: Int @Binding var text: String @FocusState.Binding var focusedField: Int? var body: some View { HStack { Text("Row \(index + 1):") TextField("", text: $text) .multilineTextAlignment(.leading) .focused($focusedField, equals: index) } .onChange(of: focusedField) { newFocus in if newFocus == index { print("TextField \(index) is in focus") } else { print("TextField \(index) lost focus") } } .padding(.vertical, 4) } } struct RowViewWithButton: View { let index: Int @Binding var text: String @FocusState.Binding var focusedField: Int? var body: some View { Button (action: { print("RowView - button selected at index \(index)") focusedField = index }) { HStack { Text("Row \(index + 1):") TextField("", text: $text) .multilineTextAlignment(.leading) .focused($focusedField, equals: index) } .onChange(of: focusedField) { newFocus in if newFocus == index { print("TextField \(index) is in focus") } else { print("TextField \(index) lost focus") } } .foregroundColor(.primary) } .buttonStyle(BorderlessButtonStyle()) .padding(.vertical, 4) } } #Preview { ContentView() .frame(width: 320, height: 250) }
2
0
307
Mar ’25
Crash with NSAttributedString in Core Data
I am trying out the new AttributedString binding with SwiftUI’s TextEditor in iOS26. I need to save this to a Core Data database. Core Data has no AttributedString type, so I set the type of the field to “Transformable”, give it a custom class of NSAttributedString, and set the transformer to NSSecureUnarchiveFromData When I try to save, I first convert the Swift AttributedString to NSAttributedString, and then save the context. Unfortunately I get this error when saving the context, and the save isn't persisted: CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600003721140> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null) Here's the code that tries to save the attributed string: struct AttributedDetailView: View { @ObservedObject var item: Item @State private var notesText = AttributedString() var body: some View { VStack { TextEditor(text: $notesText) .padding() .onChange(of: notesText) { item.attributedString = NSAttributedString(notesText) } } .onAppear { if let nsattributed = item.attributedString { notesText = AttributedString(nsattributed) } else { notesText = "" } } .task { item.attributedString = NSAttributedString(notesText) do { try item.managedObjectContext?.save() } catch { print("core data save error = \(error)") } } } } This is the attribute setup in the Core Data model editor: Is there a workaround for this? I filed FB17943846 if someone can take a look. Thanks.
2
0
200
Jun ’25
Crash with NSAttributedString in Core Data
I am trying out the new AttributedString binding with SwiftUI’s TextEditor in iOS26. I need to save this to a Core Data database. Core Data has no AttributedString type, so I set the type of the field to “Transformable”, give it a custom class of NSAttributedString, and set the transformer to NSSecureUnarchiveFromData When I try to save, I first convert the Swift AttributedString to NSAttributedString, and then save the context. Unfortunately I get this error when saving the context, and the save isn't persisted: CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600003721140> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null) Here's the code that tries to save the attributed string: struct AttributedDetailView: View { @ObservedObject var item: Item @State private var notesText = AttributedString() var body: some View { VStack { TextEditor(text: $notesText) .padding() .onChange(of: notesText) { item.attributedString = NSAttributedString(notesText) } } .onAppear { if let nsattributed = item.attributedString { notesText = AttributedString(nsattributed) } else { notesText = "" } } .task { item.attributedString = NSAttributedString(notesText) do { try item.managedObjectContext?.save() } catch { print("core data save error = \(error)") } } } }
2
0
106
Jun ’25
Swift Playground crashes
I'm trying to use the new #Playground feature in Xcode, but it keeps crashing in the canvas. I am testing on Xcode 26.0 beta 4, on both macOS 15 and macOS26 beta 4. How do I figure out what's going on? I also have a few SwiftUI previews in my project, which also crashes if I try to preview them. They're not in any active tab right now in Xcode. But the #Playground feature still doesn't work. I also don't get a crash when working on a #Playground in a different project. I've tried cleaning out Derived Data and restarting the Mac / Xcode, all with no avail. How do I track down what's causing this? Do previews and playground run on the same engine? System Integrity Protection: enabled Triggered by Thread: 0 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: Namespace OBJC, Code 1, Thread 0 Crashed: 0 libsystem_kernel.dylib 0x100634ad0 __abort_with_payload + 8 1 libsystem_kernel.dylib 0x100659dc0 abort_with_payload_wrapper_internal + 100 2 libsystem_kernel.dylib 0x100659d5c abort_with_reason + 28 3 libobjc.A.dylib 0x18009bd08 _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 112 4 libobjc.A.dylib 0x18009bc98 _objc_fatal(char const*, ...) + 28 5 libobjc.A.dylib 0x18008be14 lookUpImpOrForward + 580 6 libobjc.A.dylib 0x180072f00 _objc_msgSend_uncached + 64 7 ??? 0x340a44048 ??? 8 CJournal 0x1001c54c4 __debug_blank_executor_run_user_entry_point + 152 9 PreviewsInjection 0x241623bf4 0x2415ff000 + 150516 10 PreviewsInjection 0x24162481c 0x2415ff000 + 153628 11 PreviewsInjection 0x241624740 __previews_injection_run_user_entrypoint + 12 12 XOJITExecutor 0x25543ad48 __xojit_executor_run_program_wrapper + 1460 13 XOJITExecutor 0x25543725c 0x255435000 + 8796 14 PreviewsInjection 0x24162468c 0x2415ff000 + 153228 15 CJournal 0x1001c4c7c __debug_blank_executor_main + 996 16 ??? 0x1003e13d0 ??? 17 dyld 0x100218924 start + 6400
2
1
186
Jul ’25
MapKit detailAccessoryView buttons not working on macOS Tahoe
Hi, I have been working with an implementation of MapKit which show custom annotations with a detailCalloutAccessoryView built using SwiftUI. This has been working fine for many years, but starting with macOS Tahoe, somehow the SwiftUI buttons in this view have stopped being tappable. I have reproduced the issue in the code below ... same code works fine in macOS14 and macOS15 now doesn't work correctly in macOS26: import Cocoa import MapKit import SwiftUI class ViewController: NSViewController { private var mapView: MKMapView! override func viewDidLoad() { super.viewDidLoad() setupMapView() } private func setupMapView() { // Create and configure the map view mapView = MKMapView() mapView.translatesAutoresizingMaskIntoConstraints = false mapView.delegate = self view.addSubview(mapView) // Pin the map to all edges of the view NSLayoutConstraint.activate([ mapView.topAnchor.constraint(equalTo: view.topAnchor), mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor), mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor), mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) // Create an annotation for San Francisco let sanFranciscoCoordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194) let annotation = MKPointAnnotation() annotation.coordinate = sanFranciscoCoordinate annotation.title = "San Francisco" annotation.subtitle = "The City by the Bay" // Add the annotation to the map mapView.addAnnotation(annotation) // Center the map on San Francisco let region = MKCoordinateRegion(center: sanFranciscoCoordinate, latitudinalMeters: 5000, longitudinalMeters: 5000) mapView.setRegion(region, animated: false) } } // MARK: - MKMapViewDelegate extension ViewController: MKMapViewDelegate { func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { let identifier = "CustomAnnotation" var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView if annotationView == nil { annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier) annotationView?.canShowCallout = true // Create the SwiftUI view for the callout let calloutView = CalloutContentView() let hostingView = NSHostingView(rootView: calloutView) hostingView.frame = NSRect(x: 0, y: 0, width: 200, height: 100) // Set the SwiftUI view as the detail callout accessory annotationView?.detailCalloutAccessoryView = hostingView } else { annotationView?.annotation = annotation } return annotationView } } // MARK: - SwiftUI Callout View struct CalloutContentView: View { var body: some View { VStack(spacing: 12) { Text("Welcome to San Francisco!") .font(.headline) .multilineTextAlignment(.center) HStack(spacing: 12) { Button(action: { print("Directions button tapped") }) { Label("Directions", systemImage: "arrow.triangle.turn.up.right.circle.fill") .font(.caption) } .buttonStyle(.borderedProminent) Button(action: { print("Info button tapped") }) { Label("Info", systemImage: "info.circle.fill") .font(.caption) } .buttonStyle(.bordered) } } .padding() .frame(width: 200) } } I've looked at other problems with Map and onTap handlers not getting called, but this is a SwiftUI view inside an AppKit MapKit annotation's callout view. Any idea of how to handle this?
2
0
129
Nov ’25
Setting CKRecord's recordChangeTag field for unit testing
Hi,I am rrying to add unit tests for my CloudKit error handling code. One of my tests requires me to set the 'recordChangeTag' property to something that's not nil (so it can simulate an existing server record) ... but I can't figure out a way how to set this. Setting a value using the record.recordChangeTag doesn't work, wont even compile. I tried using [record setObject: @"aad" forKey:@"recordChangeTag"]; but even that fails at run-time, failing with this:"caught "NSInvalidArgumentException", ""recordChangeTag" is a reserved key name"Is there any other way to set this? I need to test some conflict-handling code, and the only way to do this sensibly is to simulate an existing server record, which you can't do without a 'recordChangeTag'.
1
0
926
Jun ’21
'NSWidgetWantsLocation' key prompts for location
Hi, I want to query the user's current location from my widget, so I added have the 'NSWidgetWantsLocation' key in my widget's Info.plist, and added the code to find the location with CLLocationManager. But now if I launch the app for the very first time, before I even interact with the widget or do anything else, I start seeing the location permissions prompt which says "Allow <MyApp> to use your location". If I ignore it for a few seconds, the prompt goes away, but it's back the next time the app launches. It makes for a poor user experience for users who just download the app to try it out, and might not care about the widget at all. Why would this be happening? Does the widget run in the background even if the user never even launched the widget-picker mode? How would I know when the user *has* opened the widget, so I can see if I need to ask for location permissions or not? Here's what I've tried: deleting the app, and then resetting Privacy prompts (same problem) setting 'NSWidgetWantsLocation' to No stops the prompt from showing up, but defeats the purpose of finding the user's location Thanks for the help.
1
0
871
Jul ’22
Resizable NSDatePicker with graphical mode
I want to add a NSDatePicker in the sidebar of my app, to help select a date , or a range of dates. I could use the standard NSDatePicker, but it only seems to come in a single size, and doesn't seem to be resizable. I've dropped the NSDatePicker component into a xib file, and added auto-layout constraints, but they don't seem to work. Is there a way to make them respond to auto-layout and be resizable? Or should I be looking for 3rd-party frameworks to integrate with (if so, any recommendations)?
Topic: UI Frameworks SubTopic: AppKit Tags:
1
0
423
Feb ’21
Core Data - do we need to add model versions?
Hi, I've been working with Core Data for a number of years, and I remember that when I needed to add attributes or entities to the data model, I had to first create a new model version, then add the new attributes/entities, and then use the "lightweight migration' flag when adding the NSPersistentStore to the NSPersistentStoreCoordinator. If it didn't add the new model version, the app would crash. I've tried adding something to my data model now after a few years, without adding a new model version in Xcode. And right now, it seems to work fine. I can read/write to the new attribute that I added to an entity, and nothing crashed. I tried this on the simulator, as well as on my device. Did something change at some point, where adding a new model version isn't a requirement for using lightweight migration? Or am I missing something? Why isn't it crashing anymore (and will it crash if I change my model without adding a new model version and ship it to production)? Thanks.
1
0
1.7k
Apr ’23
Question about using camera-to-text functionality
Hi, I just saw the "Use the camera for keyboard input in your app" talk, and had a question about it's capability that wasn't covered. From what I could tell, you have to designate a particular UITextField / UITextView as the 'target' (or is it 'responder'?). If I want to parse different types of content (name, email, phone number) into different UITextFields, for e.g to fill out a form ... how would that work? I don't want the user to launch the camera 3 times, one for each text field. Or would it be best to dump the contents into a UITextView and then have it parse the contents and detect the content types? Thanks.
1
0
620
Jun ’21
Looking for a solution to replace UILocalNotifications
Hi, I am using the (deprecated) UILocalNotification class in my app right now, because it fulfills a need that the UserNotification framework doesn't fulfill even 5 years after it was introduced. In my app, users can setup 'reminders' for different tasks, and those could be one-off tasks, or repeating tasks that start from a particular date/time. The UserNotifications system doesn't work with the latter requirement; it doesn't allow for you to setup a repeating alert which starts at a specific date/time. You can either setup a one-off alert in the future, or you can setup a repeating alert which starts as soon you set it up. As an example, I want to be reminded to call a friend of mine every week, from July 10th onward ... with the UserNotification framework, setting a 'repeat' will mean it'll fire an alert every week, starting from today. So what's the best way to build a solution to this? Is there a way to 'intercept' the alert before it's shown (if it's before the date we want it to start firing)? Should I be looking at some 3rd-party services to do this remotely? Thanks!
1
0
737
Jun ’21
UserNotifications local notifications limits
Hi, With iOS15, is there still a limit for how many UserNotifications can be scheduled locally on a device? A lot of places suggest that the limit is for 64 notifications at a time, and this limit has been there since UILocalNotifications were a thing. Has that changed at all? Considering that modern devices are so much more powerful than in the past, one would imagine that they should be handle more than a few local notifications in the system. I filed a Radar for this 5 years ago, which was changed to this Feedback Request: FB5978935
1
0
2.7k
Jun ’21