Search results for

Swift 6

49,192 results found

Post

Replies

Boosts

Views

Activity

Swift playground + metal crashes on swift 6
Following code crashes (sigsegv in lldb-rpc-server) when run as swift 6, but runs correctly when run as swift 5 (from Metal by tutorials): import PlaygroundSupport import MetalKit print(start) guard let device = MTLCreateSystemDefaultDevice() else { fatalError(GPU is not supported) } let frame = CGRect(x: 0, y: 0, width: 600, height: 600) let view = MTKView(frame: frame, device: device) view.clearColor = MTLClearColor(red: 1, green: 1, blue: 0.8, alpha: 1) let allocator = MTKMeshBufferAllocator(device: device) let mdlMesh = MDLMesh(sphereWithExtent: [0.75,0.75,0.75], segments: [100, 100], inwardNormals: false, geometryType: .triangles, allocator: allocator) let mesh = try MTKMesh(mesh: mdlMesh, device: device) guard let commandQueue = device.makeCommandQueue() else { fatalError(Could not create a command queue) } let shader = #include using namespace metal; struct VertexIn { float4 position [[attribute(0)]]; }; vertex float4 vertex_main(const VertexIn vertex_in [[stage_in]]) { return verte
1
0
366
Jan ’25
Handling Main Actor-Isolated Values with `PHPhotoLibrary` in Swift 6
Hello, I’m encountering an issue with the PHPhotoLibrary API in Swift 6 and iOS 18. The code I’m using worked fine in Swift 5, but I’m now seeing the following error: Sending main actor-isolated value of type '() -> Void' with later accesses to nonisolated context risks causing data races Here is the problematic code: Button(Save to Camera Roll) { saveToCameraRoll() } ... private func saveToCameraRoll() { guard let overlayFileURL = mediaManager.getOverlayURL() else { return } Task { do { let status = await PHPhotoLibrary.requestAuthorization(for: .addOnly) guard status == .authorized else { return } try await PHPhotoLibrary.shared().performChanges({ if let creationRequest = PHAssetCreationRequest.creationRequestForAssetFromVideo(atFileURL: overlayFileURL) { creationRequest.creationDate = Date() } }) await MainActor.run { saveSuccessMessage = Video saved to Camera Roll successfully } } catch { print(Error saving video to Camera Roll: (error.localizedDescription)) } } } Problem Description:
1
0
2.2k
Sep ’24
ARKit delegate code broken by Swift 6
I'm porting over some code that uses ARKit to Swift 6 (with Complete Strict Concurrency Checking enabled). Some methods on ARSCNViewDelegate, namely Coordinator.renderer(_:didAdd:for:) among at least one other is causing a consistent crash. On Swift 5 this code works absolutely fine. The above method consistently crashes with _dispatch_assert_queue_fail. My assumption is that in Swift 6 a trap has been inserted by the compiler to validate that my downstream code is running on the main thread. In Implementing a Main Actor Protocol That’s Not @MainActor, Quinn “The Eskimo!” seems to address scenarios of this nature with 3 proposed workarounds yet none of them seem feasible here. For #1, marking ContentView.addPlane(renderer:node:anchor:) nonisolated and using @preconcurrency import ARKit compiles but still crashes :( For #2, applying @preconcurrency to the ARSCNViewDelegate conformance declaration site just yields this warning: @preconcurrency attribute on conformance to 'ARSCNViewDel
1
0
621
Oct ’24
Logic Pro cannot load v3 audio unit with framework compiled with Swift 6
Sequoia 15.4.1 (24E263) XCode: 16.3 (16E140) Logic Pro: 11.2.1 I’ve been developing a complex audio unit for Mac OS that works perfectly well in its own bespoke host app and is now well into its beta testing stage. It did take some effort to get it to work well in Logic Pro however and all was fine and working well until: The AU part is an empty app extension with a framework containing its code. The framework contains Swift code for the UI and C code for the DSP parts. When the framework is compiled using the Swift 5 compiler the AU will run in Logic with no problems. (I should also mention that AU passes the most strict auval tests). But… when the framework is compiled with Swift 6 Logic Pro cannot load it. Logic displays a message saying the audio unit could not be loaded and to contact the developer. My own host app loads the AU perfectly well with the Swift 6 version, so I know there’s nothing wrong with the audio unit. I cannot find any differences in any of the built
1
0
301
Jul ’25
What's the best way to handle view controller teardowns in Swift 6?
Previously we could have some code in deinit that tears down local state: class ViewController: UIViewController { var displayLink: CADisplayLink? deinit { displayLink?.invalidate() } } However this doesn't work in Swift 6 because we cannot access property 'displayLink' with a non-sendable type 'CADisplayLink?' from non-isolated context in deinit. What's the right way to resolve this? Is the following a reasonable approach using Task to create an async context? deinit { Task { await MainActor.run { displayLink?.invalidate() } } }
0
0
842
Jun ’22
Buttons not clickable after installing the app with Swift 6
Does anyone have a problem with buttons not clickable in the lists of elements? If I have a list of 30 elements, some of them are clickable and some not. The button is a basic button that prints something in the console. After refresh, click ability is changed but still some clickable and some not. It appears always when compiling with Swift 6. My colleague has the old Xcode 15.4 with Swift 5 and when he installs exactly the same code -> buttons and lists work just fine. I noticed some similar issues with onTapGesture on StackOverflow but my problem is a button. However, I have the same problem with onTapGesture (where I use it) in some of my View components and changing it with highPriorityGesture will not solve the problem since I can't click on the child elements of those Views anymore... I'm using Xcode 16.2 and iOS 18.2. Does anyone have an idea how to solve this?
Topic: UI Frameworks SubTopic: SwiftUI
1
0
382
Dec ’24
AVCam sample code build errors in Swift 6
The AVCam sample code by Apple fails to build in Swift 6 language settings due to failed concurrency checks ((the only modification to make in that code is to append @preconcurrency to import AVFoundation). Here is a minimally reproducible sample code for one of the errors: import Foundation final class Recorder { var writer = Writer() var isRecording = false func startRecording() { Task { [writer] in await writer.startRecording() print(started recording) } } func stopRecording() { Task { [writer] in await writer.stopRecording() print(stopped recording) } } func observeValues() { Task { for await value in await writer.$isRecording.values { isRecording = value } } } } actor Writer { @Published private(set) public var isRecording = false func startRecording() { isRecording = true } func stopRecording() { isRecording = false } } The function observeValues gives an error: Non-sendable type 'Published.Publisher' in implicitly asynchronous access to actor-isolated property '$isRecording' cannot cross actor
3
0
459
Jan ’25
Swift 6 concurrency error of passing sending closure
I am getting this error in a couple of places in my code with Task closure after setting Swift 6 as Language version in XCode. Passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure Below is minimally reproducible sample code. import Foundation final class Recorder { var writer = Writer() func startRecording() { Task { await writer.startRecording() print(started recording) } } func stopRecording() { Task { await writer.stopRecording() print(stopped recording) } } } actor Writer { var isRecording = false func startRecording() { isRecording = true } func stopRecording() { isRecording = false } } While making the class Recorder as Actor would fix the problem, I fear I will have to make too many classes as Actors in the class and in my scenario, there could be performance implications where real time audio and video frames are being processed. Further, I don't see any race condition in the code above. Does the error talk
0
0
1.1k
Jan ’25
Seriously? I can't deploy my demo to iPad cus swift 6?
Okay everyone who click into or just pass by this post ,to cut a farrrirly long story short ,here is the thing... I was devloping my app in the playground on my Mac , which was building for the iPad, In the early time of real machine commissioning(through the Xcode ),everything is okay everything is okay.. well,mabe it's time to deploy my app to the playground in ipad! Then,to top it all off🤣,then playground tell me (In case that you can't understand chinese and creat ambiguity ) emm that's too tight...,so I can only got back to the Xcode changing my language version to swift 5 then..... Noting change .... and I think err.. in order to properly deploy app to iPad ,I had to rework my code with swift 5! So, I almost fell on my knees ,can somebody who in charge of the playground ,can somebody who in charge of the playground ,just ,just! shove swift 6 in the playground (as long as it make my code run anyway), otherwise there's no way to debug it! please please plase!
1
0
824
Oct ’24
Issues with @preconcurrency and AVFoundation in Swift 6 on Xcode 16.1/iOS 18 (Worked fine in Swift 5)
Question: I'm working on a project in Xcode 16.1, using Swift 6 with iOS 18. My code is working fine in Swift 5, but I'm running into concurrency issues when upgrading to Swift 6, particularly with the @preconcurrency attribute in AVFoundation. Here is the relevant part of my code: import SwiftUI @preconcurrency import AVFoundation struct OverlayButtonBar: View { ... let audioTracks = await loadTracks(asset: asset, mediaType: .audio) ... // Tracks are extracted before crossing concurrency boundaries private func loadTracks(asset: AVAsset, mediaType: AVMediaType) async -> [AVAssetTrack] { do { return try await asset.load(.tracks).filter { $0.mediaType == mediaType } } catch { print(Error loading tracks: (error)) return [] } } } Issues: When using @preconcurrency, I get the warning: @preconcurrency attribute on module AVFoundation has no effect. Suggested fix by Xcode is: Remove @preconcurrency. But if I remove @preconcurrency, I get both a warning and an error: Warning: Add '@prec
1
0
2.4k
Sep ’24
Need Help Updating a Custom WireGuard SPM for Xcode 16 & Swift 6
Hey iOS Dev's, I’m currently working on a Swift Package Manager (SPM) for WireGuard, originally developed by a previous team member. It was working fine in Xcode 15.2, but after upgrading to Xcode 16 and Swift 6, I need to update the SPM to ensure compatibility with my base projects and other projects relying on it. With Apple making Xcode 16 mandatory for app submissions starting April 24, this has become an urgent issue. I’ve searched extensively but haven’t found a working solution yet. Has anyone faced similar challenges with Swift 6 migration and SPM updates? Any insights, best practices, or debugging tips would be greatly appreciated! Let’s connect and collaborate—I’d love to discuss possible solutions! 😊 #iOSDevelopment #Swift6 #Xcode16 #SPM #WireGuard #iOS #Swift #SoftwareEngineering #AppStore
0
0
62
Apr ’25
WatchConnectivity Swift 6 - Incorrect actor executor assumption
I am trying to migrate a WatchConnectivity App to Swift6 and I found an Issue with my replyHandler callback for sendMessageData. I am wrapping sendMessageData in withCheckedThrowingContinuation, so that I can await the response of the reply. I then update a Main Actor ObservableObject that keeps track of the count of connections that have not replied yet, before returning the data using continuation.resume. ... @preconcurrency import WatchConnectivity actor ConnectivityManager: NSObject, WCSessionDelegate { private var session: WCSession = .default private let connectivityMetaInfoManager: ConnectivityMetaInfoManager ... private func sendMessageData(_ data: Data) async throws -> Data? { Logger.shared.debug(called on Thread (Thread.current)) await connectivityMetaInfoManager.increaseOpenSendConnectionsCount() return try await withCheckedThrowingContinuation({ continuation in self.session.sendMessageData( data, replyHandler: { data in Task { await self.connectivityMetaInfoManager .decreaseOpenSendConnectionsC
3
0
1.1k
Dec ’24
Reply to Can SceneKit be used with Swift 6 Concurrency ?
I just converted my code to Swift 6 today. My SceneKit game kept crashing on launch. I figured out that simply calling this code ship.runAction(.customAction(duration: 1, action: { _, _ in })) causes a crash with Swift 6, while it works with Swift 5. Another sign that SceneKit is not ready for Swift 6. I filed FB15570385.
Topic: Graphics & Games SubTopic: SceneKit Tags:
Oct ’24
Compiler exception when using Binding and Swift 6
In my code I use a binding that use 2 methods to get and get a value. There is no problem with swift 5 but when I swift to swift 6 the compiler fails : Here a sample example of code to reproduce the problem : `import SwiftUI struct ContentView: View { @State private var isOn = false var body: some View { VStack { Image(systemName: globe) .imageScale(.large) .foregroundStyle(.tint) Text(Hello, world!) Toggle(change it, isOn: Binding(get: getValue, set: setValue(_:))) } .padding() } private func getValue() -> Bool { isOn } private func setValue(_ value: Bool) { isOn = value } }` Xcode compiler log error : 1. Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5) 2. Compiling with the current language version 3. While evaluating request IRGenRequest(IR Generation for file /Users/xavierrouet/Developer/TestCompilBindingSwift6/TestCompilBindingSwift6/ContentView.swift) 4. While emitting IR SIL function @$sSbScA_pSgIeAghyg_SbIeAghn_TR. for <<debugloc at <com
3
0
194
Aug ’25