Search results for

Swift 6

49,194 results found

Post

Replies

Boosts

Views

Activity

Reply to NSHostingView Not Working With Swift 6.0
I did some more testing by adding a regular NSView to the NSViewController for an NSWindow along with an NSHostingView (treated by AppKit Integration as an NSView). What I found is that the regular instances of NSView() accept user interaction but the NSHostingView gets ignored even though it is a return type of NSView. Somehow between Swift 5 and 6, NSHostingView is only partially usable now. You can use it to render images to an NSWindow but can't interact with it any longer. Is there something different in the NSHostingView return type of NSView that somehow got reconfigured in the background so as to prevent user interaction in Swift 6? NSHostingView functionally in Swift 5 somehow got degraded when switching to Swift 6.
Jul ’24
Swift Concurrency: Calling @MainActor Function from Protocol Implementation in Swift 6
I have a Settings class that conform to the TestProtocol. From the function of the protocol I need to call the setString function and this function needs to be on the MainActor. Is there a way of make this work in Swift6, without making the protocol functions running on @MainActor The calls are as follows: class Settings: TestProtocol{ var value:String = @MainActor func setString( _ string:String ){ value = string } func passString(string: String) { Task{ await setString(string) } } } protocol TestProtocol{ func passString( string:String ) }
1
0
142
May ’25
Swift 6 concurrency - Xcode 16b5 - init() is always nonisolated?
I noticed a change from previous betas when I attempted to compile my code with Xcode 16 beta 5. If I have a class that is MainActor isolated, and it overrides init(), it looks like this init is always considered nonisolated now, even for a MainActor isolated class. This was not the case before. For example, I have a class that inherits from NSScroller. It defines a default initializer init() which calls the designated initializer - super.init(frame:CGRect()). This is apparently not allowed right now. If that's the case, how can one even default-initialize a class??? It also doesn't let me initialize other properties, since everything is MainActor isolated. Here's an abbreviated example. class MyCustomScroller : NSScroller { init () { super.init(frame: CGRect()) scrollerStyle = .overlay alphaValue = 0 } } This was allowed in prior betas. However, in beta 5, all 3 lines of my init generates an error such as: Call to main actor-isolated initializer 'init(frame:)' in a synchronous nonisolated context or Main act
5
0
2.5k
Aug ’24
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
Swift 6 Migration error in Sample code (Updating an app to use strict concurrency sample code) provided by Apple.
Updating an app to use strict concurrency is not compiling in Swift 6 with strict concurrency enabled. I am getting the following error in Xcode Version 16.0 (16A242d). private func queryHealthKit() async throws -> ( [HKSample]?, [HKDeletedObject]?, HKQueryAnchor? ) { try await withCheckedThrowingContinuation { continuation in // Create a predicate that returns only samples created within the last 24 hours. let endDate = Date() let startDate = endDate.addingTimeInterval(-24.0 * 60.0 * 60.0) let datePredicate = HKQuery.predicateForSamples( withStart: startDate, end: endDate, options: [.strictStartDate, .strictEndDate]) // Create the query. let query = HKAnchoredObjectQuery( type: caffeineType, predicate: datePredicate, anchor: anchor, limit: HKObjectQueryNoLimit ) { (_, samples, deletedSamples, newAnchor, error) in // When the query ends, check for errors. if let error { continuation.resume(throwing: error) } else { continuation.resume(returning: (samples, deletedSamples, newAnchor)) } } store.exec
2
0
1.5k
Sep ’24
Stored property 'base' of 'Sendable'-conforming struct 'AnyShape' has non-sendable type '(CGRect) -> Path'; this is an error in the Swift 6 language mode
Since I updated my project I'm getting this error Stored property 'base' of 'Sendable'-conforming struct 'AnyShape' has non-sendable type '(CGRect) -> Path'; this is an error in the Swift 6 language mode I get this error at that struct, more specifically on the base variable public struct AnyShape: Shape { private var base: (CGRect) -> Path public init(shape: S) { base = shape.path(in:) } public func path(in rect: CGRect) -> Path { base(rect) } } I have no idea how to solve this issue, I've been looking on the internet for same issues and get nothing yet
1
0
1.6k
Sep ’24
Reply to Implement UNUserNotificationCenterDelegate in iOS app using Swift6
My hunch is that the UNUserNotificationCenter code hasn't gotten the Swift 6/strict concurrency checking treatment by Apple yet. I encountered a similar problem with QLPreviewControllerDelegate and learned of a syntax where you can prepend @preconcurrency to the protocol conformance: final class NotificationServiceDelegate: UIResponder, UIApplicationDelegate, @preconcurrency UNUserNotificationCenterDelegate ... This will let you remove the nonisolated from the protocol methods and fix (or at least silence) the error. A side note for those reading, you'll want to use the async versions of User Notification methods in Swift 6 code where available. The completion-handler-based methods can crash with a __dispatch_queue_assert assertion.
Feb ’25
GameplayKit usage with Swift 6: Call to main actor-isolated instance method 'run' in a synchronous nonisolated context
Hi there, With a couple of other developers we have been busy with migrating our SpriteKit games and frameworks to Swift 6. There is one issue we are unable to resolve, and this involves the interaction between SpriteKit and GameplayKit. There is a very small demo repo created that clearly demonstrates the issue. It can be found here: https://github.com/AchrafKassioui/GameplayKitExplorer/blob/main/GameplayKitExplorer/Basic.swift The relevant code also pasted here: import SwiftUI import SpriteKit struct BasicView: View { var body: some View { SpriteView(scene: BasicScene()) .ignoresSafeArea() } } #Preview { BasicView() } class BasicScene: SKScene { override func didMove(to view: SKView) { size = view.bounds.size anchorPoint = CGPoint(x: 0.5, y: 0.5) backgroundColor = .gray view.isMultipleTouchEnabled = true let entity = BasicEntity(color: .systemYellow, size: CGSize(width: 100, height: 100)) if let renderComponent = entity.component(ofType: BasicRenderComponent.self) { addChild(renderComponent.sprite)
2
0
1.1k
Oct ’24