Search results for

Swift 6

49,183 results found

Post

Replies

Boosts

Views

Activity

Swift 6 and NSPersistentCloudKitContainer
Hello all! I'm porting a ios15+ swiftui app to be compatible with Swift 6 and enabling strict concurrency checking gave me a warning that will be an error when switching to swift 6. I'm initializing a persistence controller for my cloud kit container: import CoreData struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: IBreviary) container.loadPersistentStores(completionHandler: { _, error in if let error = error as NSError? { fatalError(Unresolved error (error), (error.userInfo)) } }) container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy container.viewContext.automaticallyMergesChangesFromParent = true } } The warning is on the merge policy: Reference to var 'NSMergeByPropertyObjectTrumpMergePolicy' is not concurrency-safe because it involves shared mutable state; this is an error in the Swift 6 language mode I have no idea how to make th
2
0
954
Sep ’24
TVTopShelfContentProvider and Swift 6 Concurrency
I have a TVTopShelfContentProvider that implements func loadTopShelfContent() async -> (any TVTopShelfContent)? When running on Xcode 26 b5 I am seeing the following error in swift 6 mode. Non-Sendable type '(any TVTopShelfContent)?' cannot be returned from nonisolated override to caller of superclass instance method 'loadTopShelfContent()' I'm not sure exactly what's changed here as it used to compile just fine but it's unclear now how I can work-around this error or how the API is supposed to be used. The following definition is enough to trigger the error in Swift 6 language mode. import TVServices class ContentProvider: TVTopShelfContentProvider { override func loadTopShelfContent() async -> (any TVTopShelfContent)? { return nil } } I can fix it by adding @preconcurrency to the TVServices import but it seems like this API is unusable currently? Or maybe it's user error on my part?
2
0
37
Aug ’25
Swift Data + Swift 6 Sendable-ity paradox
Xcode 16 beta 3 Assume a SwiftData model starts like this and has a few more properties like a name and creation date (these are immaterial to my main question. @Model final class Batch: Identifiable, Sendable { @Attribute(.unique) var id: UUID //... more stuff The combination of Swift 6 (or Swift 5 with warnings enabled) and SwiftData seem to provide a paradox: Swift 6 complains when the id is a let: Cannot expand accessors on variable declared with 'let'; this is an error in the Swift 6 language mode Swift 6 complains when the id is a var: Stored property '_id' of 'Sendable'-conforming class 'Batch' is mutable; this is an error in the Swift 6 language mode Removing Sendable may be one solution but defeats the purpose and causes warnings elsewhere in the app about the model not being Sendable. Is there an obvious fix? Am I as a newbie (to the combination of Swift 6 and SwiftData) missing an entire architectural step of using ModelActor somewhere?
1
0
3.7k
Aug ’24
com.Metal.CompletionQueueDispatch crash in Swift 6
I have a photo editing app which uses a simple Metal Render to display CIFilter output images. It works just fine in Swift 5 but in Swift 6 it crashes on starting the Metal command buffer with an error in the Queue : com.Metal.CompletionQueueDispatch (serial). The crash is occurring before I can debug.. I changed the command buffer to report MTLCommandBufferDescriptorStatus errorOptions = .encoderExecutionStatus. No luck with getting insight into the source of the crash.. Likewise the error is happening before any of the usual Metal debug tools are enabled. The Metal render works just fine in Swift 5 and also works fine with almost all of the Swift Compiler Upcoming feature flags set to Yes. [The Default Internal Imports flag is still No. (the number of compile errors with this setting is absolutely scary! but that's another topic) Do you have any suggestions on debugging or ideas on why the Metal library is crashing in Swift 6??? Everything is current release vers
1
0
612
Dec ’24
Swift 6 AVAssetImageGenerator generateCGImagesAsynchronously
I have the following piece of code that works in Swift 5 func test() { let url = Bundle.main.url(forResource: movie, withExtension: mov) let videoAsset = AVURLAsset(url: url!) let t1 = CMTime(value: 1, timescale: 1) let t2 = CMTime(value: 4, timescale: 1) let t3 = CMTime(value: 8, timescale: 1) let timesArray = [ NSValue(time: t1), NSValue(time: t2), NSValue(time: t3) ] let generator = AVAssetImageGenerator(asset: videoAsset) generator.requestedTimeToleranceBefore = .zero generator.requestedTimeToleranceAfter = .zero generator.generateCGImagesAsynchronously(forTimes: timesArray ) { requestedTime, image, actualTime, result, error in let img = UIImage(cgImage: image!) } } When I compile and run it in Swift 6 it gives a EXC_BREAKPOINT (code=1, subcode=0x1021c7478) I understand that Swift 6 adopts strict concurrency. My question is if I start porting my code, what is the recommended way to change the above code? Rgds, James
5
0
1.1k
Aug ’24
Is Metal usable from Swift 6?
Hello ladies and gentlemen, I'm writing a simple renderer on the main actor using Metal and Swift 6. I am at the stage now where I want to create a render pipeline state using asynchronous API: @MainActor class Renderer { let opaqueMeshRPS: MTLRenderPipelineState init(/*...*/) async throws { let descriptor = MTLRenderPipelineDescriptor() // ... opaqueMeshRPS = try await device.makeRenderPipelineState(descriptor: descriptor) } } I get a compilation error if try to use the asynchronous version of the makeRenderPipelineState method: Non-sendable type 'any MTLRenderPipelineState' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary Which is understandable, since MTLRenderPipelineState is not Sendable. But it looks like no matter where or how I try to access this method, I just can't do it - you have this API, but you can't use it, you can only use the synchronous versions. Am I missing something or is Metal just not usable with Swift 6 right now?
1
0
569
Feb ’25
Swift 6 crash calling requestAutomaticPassPresentationSuppression
I found a similar problem here https://developer.apple.com/forums/thread/764777 and I could solve my problem by wrapping the call to requestAutomaticPassPresentationSuppression in a call to DispatchQueue.global().async. But my question is if this is really how things should work. Even with strict concurrency warnings in Swift 6 I don't get any warnings. Just a runtime crash. How are we supposed to find these problems? Couldn't the compiler assist with a warning/error. Why does the compiler make the assumptions it does about the method that is declared like this: @available(iOS 9.0, *) open class func requestAutomaticPassPresentationSuppression(responseHandler: @escaping (PKAutomaticPassPresentationSuppressionResult) -> Void) -> PKSuppressionRequestToken Now that we have migrated to Swift 6 our code base contains a bunch of unknown places where it will crash as above.
2
0
455
Feb ’25
CommandGroup, Xcode 16b1, and Swift 6
I suspect this will be a wait for the next beta item, but thought I'd throw it out here in case anyone knows of a workaround. Mac app compiling under Xcode 16 beta 1. Trying to get rid of all warning that would stop the adoption of Swift 6 -- Strict Concurrency Checking is set to Complete. I'm down to one warning before I can enable swift 6. SwiftUI.Commands Main actor-isolated static method '_makeCommands(content:inputs:)' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode That's because I've added menu commands to the app. It's very easy to reproduce. import SwiftUI @main struct CommandApp: App { var body: some Scene { WindowGroup { ContentView() } .commands { HelpCommand() } } } struct HelpCommand: Commands { var body: some Commands { CommandGroup(replacing: .help) { Button(Help me) { // } } } } The suggested fix is telling me what change I should make ot _makeCommands. At least that is how I'm reading it.
0
0
575
Jun ’24
Swift 6 actor error in didReceiveRemoteNotification of UIApplicationDelegate
From Xcode 16.0 Beta I am getting the following error at didReceiveRemoteNotification of UIApplicationDelegate protocol: Non-sendable type '[AnyHashable : Any]' in parameter of the protocol requirement satisfied by main actor-isolated instance method 'application(_:didReceiveRemoteNotification:)' cannot cross actor boundary; this is an error in the Swift 6 language mode Generic struct 'Dictionary' does not conform to the 'Sendable' protocol (Swift.Dictionary) How can I fix this warning before moving to Swift 6 mode.
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
2.3k
Jun ’24
Xcode 16.3 Swift 6
I am migrating your application to Xcode 16 and swift 6 and in the process of creating the build I am stumbling over this issue. I have tried several fixes recommended by AI which didn't solve this issue. The pods have been updated to the latest supported platform versions. I appreciate some guidance on how to resolve this compiling issue. clang++: error: SDK does not contain 'libarclite' at the path '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a'; try increasing the minimum deployment target Command Ld failed with a nonzero exit code
1
0
289
Jun ’25
TipKit vs. Swift 6 + Concurrency
I'm trying to convert my project to use Swift 6 with Complete Concurrency in Xcode 16 beta 1. The project uses TipKit, but I'm getting compile errors when trying to use the TipKit Parameters feature. Here is an example of the type of error I'm seeing (Note that this code from https://developer.apple.com/documentation/tipkit/highlightingappfeatureswithtipkit): struct ParameterRuleTip: Tip { // Define the app state you want to track. @Parameter static var isLoggedIn: Bool = false Static property '$isLoggedIn' is not concurrency-safe because it is non-isolated global shared mutable state. Is there a new pattern for supporting TipKit Parameters in Swift 6 with Complete Concurrency enabled? There is no obvious suggestion for how to fix this. The latest WWDC 2024 TipKit doesn't appear to have any solution(s).
7
0
1.5k
Jun ’24
Using Core Data with the Swift 6 language mode
I'm starting to work on updating my code for Swift 6. I have a number of pieces of code that look like this: private func updateModel() async throws { try await context.perform { [weak self] in // do some work } } After turning on strict concurrency checking, I get warnings on blocks like that saying Sending 'self.context' risks causing data races; this is an error in the Swift 6 language mode. What's the best way for me to update this Core Data code to work with Swift 6?
4
0
2.8k
Jun ’24
Issue with Swift 6 migration issues
We are migrating to swift 6 from swift 5 using Xcode 16.2. we are getting below errors in almost each of our source code files : Call to main actor-isolated initializer 'init(storyboard:bundle:)' in a synchronous non isolated context Main actor-isolated property 'delegate' can not be mutated from a nonisolated context Call to main actor-isolated instance method 'register(cell:)' in a synchronous nonisolated context Call to main actor-isolated instance method 'setup()' in a synchronous nonisolated context Few questions related to these compile errors. Some of our functions arguments have default value set but swift 6 does not allow to set any default values. This requires a lot of code changes throughout the project. This would be lot of source code re-write. Using annotations like @uncheck sendable , @Sendable on the class (Main actor) name, lot of functions within those classes , having inside some code which coming from other classes which also showing main thread issue even we us
1
0
139
May ’25
Swift 6 Minimum Requirement for App Store
Good afternoon, all! I was wondering if there was a timeline for when the App Store and/or TestFlight will drop support for Swift 5? I know Swift 6 was released last year and historically App Store requires a certain SDK minimum for upload. I was wondering if any SDK update was on the docket that would effectively force applications onto Swift 6? Looking at past releases, I had estimated mid to late 2026, but I wanted to confirm? Swift 4 Released September 2017 Became the default SDK in Xcode 9 Strongly encouraged via the iOS 12 SDK in late 2018 Essentially required by early 2019 Swift 5 Released March 2019 Became the default SDK in Xcode 10.2 Strongly encouraged via the iOS 12.1 SDK in early 2019 Essentially required by late 2020 Swift 6 Released June 2024 Became the default SDK in Xcode 16 Strongly encouraged via the iOS 18 SDK in April 2025 **Essentially required by mide-late 2026 ?? ** Thank you in advance!
4
0
122
Aug ’25
Widget Intent Configuration doesn't work in Swift 6
macOS: Sequoia Xcode: 16.1 I am working on a macOS app and it has a widget feature. When I use Swift 6 (Build Settings > Swift Language Version) in IntentExtension, the intent configuration won't show up in macOS Sequoia. If I downgrade to Swift 5, it works without any other changes. Is it a bug or am I missing something? How can I use Swift 6 with IntentExtension.
2
0
744
Nov ’24