Search results for

Swift 6

49,193 results found

Post

Replies

Boosts

Views

Activity

LocalAuthentication like Face ID crashes using swift 6 iOS 18.1
Hello, I have been implementing faceID authentication using LocalAuthentication, and I've noticed that if i use swift 5 this code compiles but when i change to swift 6 it gives me a crash saying this compile error: i have just created this project for this error purpose so this is my codebase: import LocalAuthentication import SwiftUI struct ContentView: View { @State private var isSuccess: Bool = false var body: some View { VStack { if isSuccess { Text(Succed) } else { Text(not succeed) } } .onAppear(perform: authenticate) } func authenticate() { let context = LAContext() var error: NSError? if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) { let reason = We need to your face to open the app context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { sucexd, error in if sucexd { let success = sucexd Task { @MainActor [success] in isSuccess = success } } else { print(error?.localizedDescription as Any) } } } else { print
2
0
808
Dec ’24
Request authorization for the notification center crash iOS app on Swift 6
Hey all! During the migration of a production app to swift 6, I've encountered a problem: when hitting the UNUserNotificationCenter.current().requestAuthorization the app crashes. If I switch back to Language Version 5 the app works as expected. The offending code is defined here class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configure() FirebaseConfiguration.shared.setLoggerLevel(.min) UNUserNotificationCenter.current().delegate = self let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { _, _ in } application.registerForRemoteNotifications() Messaging.messaging().delegate = self return true } } The error is depicted here: I have no idea how to fix this. Any help will be really appreciated thanks in advance
19
0
5.3k
Sep ’24
Crash with Progress type, Swift 6, iOS 18
We are getting a crash _dispatch_assert_queue_fail when the cancellationHandler on NSProgress is called. We do not see this with iOS 17.x, only on iOS 18. We are building in Swift 6 language mode and do not have any compiler warnings. We have a type whose init looks something like this: init( request: URLRequest, destinationURL: URL, session: URLSession ) { progress = Progress() progress.kind = .file progress.fileOperationKind = .downloading progress.fileURL = destinationURL progress.pausingHandler = { [weak self] in self?.setIsPaused(true) } progress.resumingHandler = { [weak self] in self?.setIsPaused(false) } progress.cancellationHandler = { [weak self] in self?.cancel() } When the progress is cancelled, and the cancellation handler is invoked. We get the crash. The crash is not reproducible 100% of the time, but it happens significantly often. Especially after cleaning and rebuilding and running our tests. * thread #4, queue = 'com.apple.root.default-qos', stop reason = EXC_BREAKPOINT (code=1, su
24
0
2.6k
Oct ’24
Under Swift 6 on Sequoia, why is ContiguousArray suddenly so slow to allocate
I generate images with command line apps in Swift on MacOS. Under the prior Xcode/MacOS my code had been running at the same performance for years. Converting to Swift 6 (no code changes) and running on Sequoia, I noticed a massive slowdown. Running Profile, I tracked it down to allow single line: var values = ContiguousArray(repeating: 0.0, count: localData.options.count) count for my current test case is 4, so its allocating 4 doubles at a time, around 40,000 times in this test. This one line takes 42 seconds out of a run time of 52 seconds. With the profile shown as: 26 41.62 s  4.8% 26.00 ms specialized ContiguousArray.init(_uninitializedCount:) 42 41.57 s  4.8% 42.00 ms _ContiguousArrayBuffer.init(_uninitializedCount:minimumCapacity:) 40730 40.93 s  4.7% 40.73 s _swift_allocObject_ 68 68.00 ms  0.0% 68.00 ms std::__1::pair swift::ConcurrentReadableHashMap::find(unsigned int const&, swift::ConcurrentReadableHashMap::IndexStorage, unsigned long, MallocTypeCacheEntry*
3
0
626
Oct ’24
Animated Custom Transitions Crash using Swift 6
When you apply an animation to a custom Transition in Swift 6, it is likely that that the app will crash with a SwiftUI.AsyncRenderer dispatch_assert_queue_fail error. Non-animated Transitions do not crash nor do animated system transitions. If you use ViewModifiers to create an AnyTransition with the .modifier(active:, identity:) static method, there is no problem. I used the example Transition in the docs for Transition to illustrate this problem. I'm using Xcode 16.2 RC and Swift 6, running iOS 18.1.1 on an iPhone 16 Pro. I've created two separate Previews that illustrate what specifically crashes the app and what doesn't as well as a workaround for this bug. func generateRandomString() -> String { let characters = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 return String((0..<10).compactMap { _ in characters.randomElement() }) } // MARK: Works extension AnyTransition { struct RotatingFadeTransitionModifier: ViewModifier { let opacity: CGFloat let rotation: Angle
3
0
474
Dec ’24
Reply to DispatchSemaphore freeze
The alignmentGuide modifier is @preconcurrency nonisolated. In Swift 6, I had to call a nonisolated function to calculate alignment, in which a certain @MainActor property was needed. That's why I tried to use a semaphore. I have switched back to Swift 5, since AVFoundation is not ready for Swift 6. The problem here is solved by removing nonisolated and semaphore. We may handle it after switching to Swift 6 in the future. Thanks.
Oct ’24
Swift 6 and 5 - Strict concurrency: complete and WKNavigationDelegate decidePolicyFor not being called.
decidePolicyFor delegate method: import WebKit @objc extension DocumentationVC { func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) Being called just alright in swift 5 minimal concurrency. Raising concurrency to complete with swift 5 or swift 6. Changing the code to avoid warnings: @preconcurrency import WebKit @objc extension DocumentationVC { func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { The delegate method is not being called. Changing back to swift 5 concurrency minimal - it is called. Looking at WKNavigationDelegate: WK_SWIFT_UI_ACTOR @protocol WKNavigationDelegate - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(WK_SWIFT_UI_ACTOR void (^)(WKNavigationActionPolicy))decisionHandler
1
0
563
Jan ’25
Swift 6 concurrency. Apple Watch App target and -disable-dynamic-actor-isolation.
I've got a watch app, still with storyboard, WKInterfaceController and WatchConnectivity. After updating it for swift 6 concurrency I thought I'd keep it for a little while without swift 6 concurrency dynamic runtime check. So I added -disable-dynamic-actor-isolation in OTHER_SWIFT_FLAGS, but it doesn't seem to have an effect for the Apple Watch target. Without manually marking callbacks where needed with @Sendable in dynamic checks seem to be in place. swiftc invocation is as (includes -disable-dynamic-actor-isolation): swiftc -module-name GeoCameraWatchApp -Onone -enforce-exclusivity=checked ... GeoCameraWatchApp.SwiftFileList -DDEBUG -enable-bridging-pch -disable-dynamic-actor-isolation -D DEBUG -enable-experimental-feature DebugDescriptionMacro -sdk /Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS11.2.sdk -target arm64_32-apple-watchos7.0 -g -module-cache-path /Users/stand/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -Xfrontend -seri
2
0
584
Jan ’25
Reply to Static property 'shared' is not concurrency-safe because it is non-isolated global shared mutable state
Hey @njsnx, This is not a bug. This is an error that is triggered when using the Swift 6 Language. Inside your target's Build Settings you can change the Swift Language Version to Swift 5 to temporarily avoid these errors. If you go this route you should enable Complete Swift Concurrency Checking to create warnings for these issues that are errors in Swift 6. The Sample Code uses Swift 5 which is why this is only an issue in your project. I'd highly encourage you to remain on Swift 6 and fix the underlying errors. We published a WWDC video and a migration guide to help you in the process: Migrate your app to Swift 6 Migrating to Swift 6 In terms of the underlying changes that are required for the Entity Gestures code I would consider refactoring the EntityGestureState shared instance to be a property on the GestureComponent. This involves changing the EntityGestureState to a Codeable struct which also requires changing some of th
Aug ’24
Xcode 16 beta 5 MainActor errors in a Swift 6 project while working in beta 4
After updating to Xcode 16.0 beta 5 (16A5221g) on macOS Sonoma 14.6 I am getting lots of errors like: Main actor-isolated property '[property name]' can not be mutated from a nonisolated context in classes that are marked as @MainActor at the class level, e.g.: @MainActor final class MyClass: AnotherClass { ... } The project uses Swift 6 and there are no errors in Xcode 16 beta 4. I tried restarting, clearing Derived Data, cleaning build folder... Anyone else encountering this issue with beta 5?
1
0
863
Aug ’24
Rewrite `UNNotificationServiceExtension` sub class into Swift 6 async await notation
I'm trying to rewrite a Swift code to Swift 6 language mode and am stuck with this problem. How do I safely pass the bestAttemptContent and contentHandler to the Task? This is from the UNNotificationServiceExtension subclass. final class NotificationService: UNNotificationServiceExtension { var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent? var customNotificationTask: Task? override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.contentHandler = contentHandler bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) guard let bestAttemptContent = bestAttemptContent else { invokeContentHandler(with: request.content) return } do { let notificationModel = try PushNotificationUserInfo(data: request.content.userInfo) guard let templatedImageUrl = notificationModel.templatedImageUrlString, let imageUrl = imageUrl(from:
2
0
435
Jan ’25
AppKit document project reports an error when opening a new document in Swift 6
In an AppKit document-based project created by Xcode, setting canConcurrentlyReadDocuments to true allows new documents to open normally in Swift 5, but switching to Swift 6 causes an error. Judging from the error message, it seems to be a threading issue, but I’m not sure how to adjust the code to support the Swift 6 environment. The project is the most basic code from an Xcode-created document-based project without any modifications, except for changing the Swift version to 6 and setting canConcurrentlyReadDocuments to true. Source code: https://drive.google.com/file/d/1ryb2TaU6IX884q0h5joJqqZwSX95Q335/view?usp=sharing AppDelegate.swift import Cocoa @main class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application } func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } func applicationSupports
1
0
526
Feb ’25
Reply to AVCam sample code build errors in Swift 6
Hello @testinstadev, Please file an enhancement request using Feedback Assistant to request that the AVCam sample be updated for Swift 6. For your minimal reproducing example, I recommend that you continue to follow-up in your thread on the Swift Forums (https://forums.swift.org/t/swift-6-concurrency-error-of-passing-sending-closure/77048). -- Greg
Jan ’25