Search results for

Swift 6

49,200 results found

Post

Replies

Boosts

Views

Activity

Reply to Function types as return types
If you make a mistake in your post you have a one-hour window in which you can edit it. If you're outside of that one hour, just reply to your original post. There's no need to create a duplicate thread for the same issue just because you didn't format something properly; that just clutters the forums. Anyway, correctly formatted: func stepForward(_ input: Int) -> Int { input + 1 } func stepBackward(_ input: Int) -> Int { input - 1 } func chooseStepFunction(backward: Bool) -> (Int) -> Int { backward ? stepBackward : stepForward } // Second version func chooseStepFunction(backward: Bool) -> (Int) -> Int { if backward { stepBackward } else { stepForward } } I don't get any errors, so this can't be the code that's causing it. The first version with the ternary operator works fine. As an aside, in Swift, if your function only does one thing then you don't need the return keyword.
Topic: Programming Languages SubTopic: Swift Tags:
2w
iPhone app Liquid Glass icon on iPad not respecting icon display mode
Hi, I'm updating my iPhone app (iPhone only) to be ready with iOS 26. I'm building my app using Xcode 26.0 beta 6 (17A5305f) and testing it on an iPad running iPadOS 26 (23A5326a). I found an issue with my new app icon updated using Icon Composer and I was able to find the issue. An iPhone only app running on iPadOS 26 doesn't use the provided app icon. It always displays the standard light icon. I just added iPad in Supported Destinations and the app icon now respect light/dark/translucent/tinted modes on the Home Screen. I submitted feedback FB19768667
1
0
139
2w
Reply to Function types as return types
It works in iOS playground, but not in MacOS playground, either Xcode 16.4 or 26.0ß6. So, that's definitely a bug you should report. You got the answer in your SO post: https://forums.swift.org/t/why-is-there-a-type-of-expression-is-ambiguous-without-a-type-annotation-error-when-using-a-ternary-operator-on-inferred-function-types-in-swift/77306/2 As said, this works: func chooseStepFunction(backward: Bool) -> (Int) -> Int { let res = oneStepBackward ? stepBackward : oneStepForward return res }
Topic: Programming Languages SubTopic: Swift Tags:
2w
Reply to Function types as return types
Thx for your reply . I am using Xcode version 16.4 and running in a playground. Just by typing these functions in the IDE (without any calls to the functions) I get the error message in the Code Review Pane. It is a blank macOS playground running on a Mac Studio M1. The code is from Apple's Swift Programming Language (5.7). Section Functions - Function types as return types.
Topic: Programming Languages SubTopic: Swift Tags:
2w
Reply to SwiftData Fatal error: Editors must register their identifiers before invoking operations on this store
Do you have a full symbolicated crash report to share? You can include crash reports directly in your post using the forums attachment feature. For any random crash related to SwiftData / Core Data, I'd suggest that you add com.apple.CoreData.ConcurrencyDebug 1 as a launch argument of the app to check if there is any violation, as discussed here. Also, I guess ConsumptionSession is Sendable? Otherwise, Xcode will give you an error if you compile with Swift 6. If you haven't used Swift 6, I'd suggest that you give it a try to see if that unveils any race condition. Best, —— Ziqiao Chen  Worldwide Developer Relations.
2w
Reply to Should ModelActor be used to populate a view?
It's unclear what LabResultDto in the code snippet is. If it is a Sendable type that wraps the data in a SwiftData model, that's fine; if it is a SwiftData model type, because a SwiftData model object is not Sendable, you won't want to pass it across actors – Otherwise, Swift 6 compiler will give you an error. For more information about this topic, see the discussion here. When using SwiftData + SwiftUI, I typically use @Query to create a result set for a view. Under the hood (of @Query), the query controller should be able to detect the changes you made from within a model actor, and trigger a SwiftUI update. Fore more information about observing SwiftData changes, see this WWDC25 video. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
2w
How to get PersistentIdentifier from a model created in a transaction?
I have a ModelActor that creates a hierarchy of models and returns a PersistentIdentifier for the root. I'd like to do that in a transaction, but I don't know of a good method of getting that identifier if the models are created in a transaction. For instance, an overly simple example: func createItem(timestamp: Date) throws -> PersistentIdentifier { try modelContext.transaction { let item = Item(timestamp: timestamp) modelContext.insert(item) } // how to return item.persistentModelID? } I can't return the item.persistentModelID from the transaction closure and even if I could, it will be a temporary ID until after the transaction is executed. I can't create the Item outside the transaction and just have the transaction do an insert because swift will raise a data race error if you then try to return item.persistentModelID. Is there any way to do this besides a modelContext.fetch* with separate unique identifiers?
2
0
154
2w
Reply to SwiftData initializing Optional Array to Empty Array
What you observed is the behavior that the framework currently has – If you save the model context right after adding a book, you will see that the relationship turns from nil to [] immediately, and that's because SwiftData makes the change when persisting the model. SwiftData does that because the default store (DefaultStore) is based on Core Data, and Core Data expresses an empty toMany relationship with an empty set. (Core Data had been implemented with Objective C long before Swift was introduced.) Having said that, if you have a different opinion about the behavior, feel free to file a feedback report – If you do so, please share your report ID here. Thanks. Best, —— Ziqiao Chen  Worldwide Developer Relations.
2w
Reply to iOS 26 Beta breaks scroll/gesture in SwiftUI chat (worked in iOS 18): Simultaneous gestures & ScrollViewReader issues
I’m also seeing this issue on my end. In our app we use Swift Charts inside a ScrollView, with simultaneous gestures applied in the chart’s overlay block (for interactions like drag/tap on data points). Since iOS 26 beta 1, this completely breaks the parent ScrollView’s vertical scrolling. This was never a problem on iOS 18, the exact same code works fine there. I also noticed that the release notes for beta 5 and beta 6 mention fixes for simultaneousGesture conflicts in scroll views, but this bug is still reproducible. So unfortunately, it’s not fixed yet, and I haven’t found a workaround so far.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
2w
mTLS : Guidance on Generating SecIdentity with Existing Private Key and Certificate
Hello, I am currently working on iOS application development using Swift, targeting iOS 17 and above, and need to implement mTLS for network connections. In the registration API flow, the app generates a private key and CSR on the device, sends the CSR to the server (via the registration API), and receives back the signed client certificate (CRT) along with the intermediate/CA certificate. These certificates are then imported on the device. The challenge I am facing is pairing the received CRT with the previously generated private key in order to create a SecIdentity. Could you please suggest the correct approach to generate a SecIdentity in this scenario? If there are any sample code snippets, WWDC videos, or documentation references available, I would greatly appreciate it if you could share them. Thank you for your guidance.
4
0
175
3w
Reply to mTLS : Guidance on Generating SecIdentity with Existing Private Key and Certificate
Step 6 - Get a digital identity from the keychain: private func getClientIdentity() -> SecIdentity? { let query: [String: Any] = [ kSecClass as String: kSecClassIdentity, kSecAttrLabel as String: MTLSTag.clientcert, // <-- match by certificate tag kSecReturnRef as String: true, kSecMatchLimit as String: kSecMatchLimitOne ] var identityRef: CFTypeRef? let status = SecItemCopyMatching(query as CFDictionary, &identityRef) if status == errSecSuccess, let identity = identityRef as! SecIdentity? { print(Retrieved client identity from Keychain) return identity } else { print(Could not retrieve client identity, status=(status)) return nil } } Usages : func updateCertificates() { // Load CA certificates (if needed for server trust validation) self.trustedCACerts = CertificateUtils.getCACertificates() self.storeCertificatesInKeychain() if let useridentity = self.getClientIdentity() { self.clientCredential = URLCredential(identity: useridentity, certificates: nil, persistence: .forSession) } }
2w
Reply to mTLS : Guidance on Generating SecIdentity with Existing Private Key and Certificate
Hello, Thank you for sharing the provided solution. I followed all the steps and used the same API set. However, while retrieving the SecIdentity using the certificate fetch API SecItemCopyMatching, I am encountering the following error: Error: Could not retrieve client identity, status = -25300 Please find the relevant code snippets below: Step 1 to 3 : Generate the private key in the keychain. Derive the public key from the private key. Export the public key bits and send that your certificate issuing infrastructure. func generateCSR(_ deviceId: String? = UserProfile.deviceId) -> String? { do { // Define subject DN for CSR let subject = try DistinguishedName([ .init(type: .NameAttributes.countryName, printableString: US), .init(type: .NameAttributes.stateOrProvinceName, printableString: stateProvince_Name), .init(type: .NameAttributes.localityName, printableString: locality_Name), .init(type: .NameAttributes.organizationName, printableString: organization_Name), .init(type: .NameAttributes.organizational
2w
Reply to Push Notification Delivery Delays and Failures on iOS Devices
When my app is in the foreground, I receive the notification at 12:13 PM (Indian Standard Time), with the APNs device token: 2bffe3f3800cd7ed7e599495e48051aa1f457ba7de52ea14ddd363bf373d3b08. However, after 6 hours, when I attempt to send a push notification at 6:00 PM (Indian Standard Time), I do not receive the notification, despite using the same APNs device token: 2bffe3f3800cd7ed7e599495e48051aa1f457ba7de52ea14ddd363bf373d3b08.
2w
iOS 26 didRegisterForRemoteNotificationsWithDeviceToken is not being called
We have an app in Swift that uses push notifications. It has a deployment target of iOS 15.0 I originally audited our app for iOS 26 by building it with Xcode 26 beta 3. At that point, all was well. Our implementation of application:didRegisterForRemoteNotificationsWithDeviceToken was called. But when rebuilding the app with beta 4, 5 and now 6, that function is no longer being called. I created a simple test case by creating a default iOS app project, then performing these additional steps: Set bundle ID to our app's ID Add the Push Notifications capability Add in application:didRegisterForRemoteNotificationsWithDeviceToken: with a print(HERE) just to set a breakpoint. Added the following code inside application:didFinishLaunchingWithOptions: along with setting a breakpoint on the registerForRemoteNotifications line: UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound]) { granted, _ in DispatchQueue.main.async { UIApplication.shared.registerForRemoteNoti
4
0
189
3w