Search results for

Swift 6

49,200 results found

Post

Replies

Boosts

Views

Activity

Reply to Metal addCompletedHandler causes crash with Swift 6 (iOS)
As the Apple Engineer stated and as in the stack overflow reply to the same question https://stackoverflow.com/questions/78999756/metal-addcompletedhandler-causes-crash-with-swift-6-ios not having @Sendable is the cause. The work around (adapting the example built into Xcode: New > Project... > Game > using Metal option): let semaphore = inFlightSemaphore commandBuffer.addCompletedHandler { @Sendable (_ commandBuffer)-> Swift.Void in semaphore.signal() } I am using a different flavour of syntax unless I am told that the above is better practice: commandBuffer.addCompletedHandler { @Sendable [weak inflightSemaphore] commandBuffer in inflightSemaphore?.signal() }
Topic: Graphics & Games SubTopic: Metal Tags:
Oct ’24
Reply to Having problems trying out the example code in this session
Hope I'm not wrong here. And I would be interested by the correct answer to this post. You are applying any to a protocol. I read that would only be availabale with Swift 6 (Xcode 14 is Swift 5.7 : https://swiftversion.net/). However, example given in SE-0352 (implemented in Swift 5.7) tells it is possible https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md And you're right, it is very similar to SE-0352, so it should work. Unless it is not yet in 14 beta ? If that may help, I noted that this works: func feedAll(_ animals: [any Animal]) { for animal in animals { print(all ->, animal) // feed(animal) if animal is Horse { feed(Horse()) } if animal is Dog { feed(Dog()) } } }
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’22
Reply to Xcode 26 - New Swift 6.2 Concurrency Sendable Closure Problems
I too, am running into this problem. I have a full reproducible example for something that works in XCode 16.4 but does not work in XCode 26, Beta 1. protocol TestProtocol:Sendable { var version: Int { get } } actor TestManager { private let migrations: TestProtocol init(migrations: TestProtocol) { self.migrations = migrations if migrations.version < 5 { } } func doSomething() async throws { if migrations.version < 5 { } } } This gives me: Main actor-isolated property 'version' can not be referenced from a nonisolated context; this is an error in the Swift 6 language mode I can store the property, then await the value before my check - which I guess is fine... func doSomething() async throws { let ver = await migrations.version if ver < 5 { } } Though this is a PITA when doing logging all over the app, or constantly accessing members of the object itself. For example, the attached screenshot shows I can't access version - despite the fact that the DatabaseMigration protocol is Sendable. Even
Topic: UI Frameworks SubTopic: AppKit Tags:
Jun ’25
Reply to Coordination of Video Capture and Audio Engine Start in iOS Development
Hi Greg, Thank you for taking the time to look into this. Unfortunately, I wasn't able to upload the file directly due to the Add File option not allowing me to select the 19.9 MB compressed zip file. To make it accessible, I’ve uploaded the file to an S3 bucket, and you can download it here: https://curvsort-public.s3.ap-south-1.amazonaws.com/AVCamBuildingACameraApp_1.zip. Please let me know once you've downloaded it, and I will delete it from the bucket. The key files with the focused issue are ESoundClassifier and CaptureService (specifically resultsObserver1 and the sections marked Works 1/2/3). To Reproduce the Issue: I am running the app on an iPhone 11 with Swift 5 and Xcode 16 Problem Case: In this case, there are no logs for the analyze and analyzeAudio methods. Working Case: To observe the working flow, comment out the code at // Does not work 1 and uncomment the three lines at // Works 3. You should then see logs for both analyze and analyzeAudio. Swift 6 Concurrency Issues: After
Sep ’24
Reply to CIFormat static var
Should all these formats be static let to suppress the warnings (future errors)? Yes, assuming you were writing this code yourself. As to what should happen with CIFormat specifically, that’s a bit tricky because it’s tied to how Swift imports C declarations and the source and binary compatibility constraints of that type. I expect that a lot of these problems will be resolved in the Apple platform SDKs that accompany Swift 6. However, it’s hard to say anything for sure because that’s The Future™ [1]. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com [1] And I can’t predict the future. See Quinn’s Top Ten DevForums Tips.
Mar ’24
Reply to Swift 6 conversion for IBOutlet
Thanks Quinn. I removed the nonisolated for IBOutlet. But, as shown in your example, I had to mark all func în a class that uses UNUserNotificationCenterDelegate as nonIsolated, such as nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) I also note in your example that you marked response for didReceive as async. I tried to, but got the error: Instance method 'userNotificationCenter(_:didReceive:withCompletionHandler:)' nearly matches optional requirement 'userNotificationCenter(_:didReceive:withCompletionHandler:)' of protocol 'UNUserNotificationCenterDelegate' with the advice to Make 'userNotificationCenter_:didReceive:withCompletionHandler:)' private to silence this warning Converting to Swift 6 is definitely not an easy ride… I'll do extensive testing.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’25
Reply to URLSessionWebSocketTask - sendPing's pongReceiveHandler called twice
Thanks Quinn, I ran into what appears to be a bug involving websocket after migrating my app to Swift 6 Concurrency. I spent a lot of time trying to work out what was wrong, and then came across your post on this topic, and concluded that it was likely a bug in URLSessionWebSocketTask, rather than in my own code. I then started looking at the Network framework, then discovered the NWWebSocket package, struggled with it for a few days, then got a clue off the Issues for that repo, and finally worked it out & got it working at 1 am this morning. It was a painful & time consuming process, but would have been far more painful without your post from June last year. Thankyou! Andrew
Apr ’25
Reply to I don't want black background in presented sheet
Thanks. I've added the test project to my GitHub here. It's an objective c storyboard hosting sample code from this year's WWDC. (which btw would be nice if this sample were swift 6 compatible so the compiler doesn't complain.) I've managed to make the background this lovely gradient, thanks for the link. My mistake was in putting the background on the body, not inside the Navigation stack. Clearly I'm used to Storyboards. But what I really want is to have it show up as a glass sheet when I present it from my objective C app, but it's not doing that, either. I tried making the background clear, but it goes back to showing up as black. How do I make it show up as glass?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’25
Reply to Possible typo in concurrency diagram (WWDC25: Elevate an app with Swift concurrency)
[quote='798011021, Blume, /thread/798011, /profile/Blume'] I noticed something in the slide/diagram that might be incorrect. [/quote] Yeah, I think you’re right. I’d appreciate you filing a bug against that video, and then posting your bug number here, just for the record. [quote='798011021, Blume, /thread/798011, /profile/Blume'] Swift 6’s concurrency model is doing a fantastic job at helping us write safer code—so thank you to the team for that! [/quote] That’s great news, and I’ll pass that along to the team. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com
Topic: Programming Languages SubTopic: Swift Tags:
2w
Reply to Help Understanding Concurrency Error with Protocol Listener and Actor
I'm not a fan of annotating everything with @MainActor. So yes, in the case of Sendable, the newValue must also conform to Sendable. I’ve written Objective-C and pre-Swift 6 code for decades that just assumed that it was. How many weird crashes has that code caused over the years? Yeah, I totally get the value of having the compiler catch these things, it's a solid direction. Personally, I can't say I've run into that many crashes from threading issues in practice, at least judging by crash metrics, things have been pretty stable. I just find it hard to get excited about spending too much time fixing compiler errors :)
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’25
Build iOS 18 with Swift 5.10
I noticed that running my app in Xcode 16 crashes often. It seems this is due to the strictness Swift 6 adds at runtime. Even after making sure the Swift Language Mode is 5 for the main target and all modules. I'm migrating to Swift 6 but I probably won't be done before iOS 18 drops so my question is. Can I still ship the app supporting iOS 18 using Xcode 15.4 and Swift 5.10?
2
0
1.1k
Aug ’24
Reply to Swift 6 concurrency. Apple Watch App target and -disable-dynamic-actor-isolation.
I would expect it to work regardless of your platform. Are you sure you applied the setting to the right target? Things can get confusing on watchOS, where you might have both an app and extension target. If your deployment target supports it, you might think about updating, per the advice in TN3157 Updating your watchOS project for SwiftUI and WidgetKit. Also, I’m curious as to why you’re going down this path. If you don’t want these checks, why use Swift 6 at all? Just switch back to the Swift 5 language mode and you’re all good [1]. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com [1] Well, you’re only good if these checks are false positives, but that’s not unheard of.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’25
Reply to @Observable in command line app
Thank you again for your help! Your advice will allow me to improve my architecture and my vision for Swift 6. I really appreciate your approach, and the use of AsyncStream (which I wasn’t familiar with) seems well-suited for event transmission in an async-await context. My application handles cancellation at the lowest level using the cancel() method of the Job object. The facade (AsyncJob object) exposes the same API. The implementation of cancellation is done with a traditional approach, which involves constantly checking if the user has requested cancellation of the job within the processing code block. Otherwise, I usually manage cancellation in an async-await context by keeping a reference to the task and calling task?.cancel. What approach do you recommend?
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’24
Reply to Pre-initialization of views?
No I am currently not using onAppear. Just on viewmodel initialization, I do all the fetching. Below you have two Views. HomeView is the parent view to PageTwo. struct HomeView: View { init() { print(Main View initialized) } var body: some View { NavigationStack { NavigationLink(Open) { PageTwo() } } } } struct PageTwo: View { init() { print(Second View initialized) } var body: some View { Text() } } When HomeView appears, I get printouts of: Main View initialized Second View initialized Both Views initialized even before I click Open to navigate me to the second view. This is did not happen before. I think around swift 6 update. Is this a bug or a feature? If a feature can it be disabled?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’24