Search results for

Swift 6

49,210 results found

Post

Replies

Boosts

Views

Activity

Cast Any to Sendable
I'm continuing with the migration towards Swift 6. Within one of our libraries, I want to check whether a parameter object: Any? confirms to Sendable. I tried the most obvious one: if let sendable = object as? Sendable { } But that results into the compiler error Marker protocol 'Sendable' cannot be used in a conditional cast. Is there an other way to do this?
5
0
1.4k
Jul ’24
Casting `[String: Any]` to `[String: any Sendable]`
I have a simple wrapper class around WCSession to allow for easier unit testing. I'm trying to update it to Swift 6 concurrency standards, but running into some issues. One of them is in the sendMessage function (docs here It takes [String: Any] as a param, and returns them as the reply. Here's my code that calls this: @discardableResult public func sendMessage(_ message: [String: Any]) async throws -> [String: Any] { return try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<[String: Any], Error>) in wcSession.sendMessage(message) { response in continuation.resume(returning: response) // ERROR HERE } errorHandler: { error in continuation.resume(throwing: error) } } } However, I get this error: Sending 'response' risks causing data races; this is an error in the Swift 6 language mode Which I think is because Any is not Sendable. I tried casting [String: Any] to [String: any Sendable] but then it says: Conditional cast from '[String : Any]' to '[String : an
3
0
1.1k
Oct ’24
MapKit not working in Swift Playgrounds
This is the complete Playground code: import MapKit import SwiftUI import PlaygroundSupport struct AddressSearchView: View { @State private var region = MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194), span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01) ) var body: some View { VStack { Map(position: .constant(MapCameraPosition.region(region))) { } .frame(height: 300) } } } struct AddressSearchView_Previews: PreviewProvider { static var previews: some View { AddressSearchView() } } PlaygroundPage.current.setLiveView(AddressSearchView()) When I try to run this I get this in the debug console: error: Couldn't look up symbols: protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI protocol witne
0
0
196
Mar ’25
Swift 3 type inference question (Xcode 8 beta 6)
Xcode 8 beta 6.I have the following code. The only difference between 1, 2, 3, 4 and 5 is what is in the 'metrics' parameter.let a = 20 // 1: This compiles. _ = NSLayoutConstraint.constraints(withVisualFormat: |[v1(a)]|, metrics: [a: 20], views: [v1: v1]) // 2: This fails with Cannot convert value of type 'Int' to expected dictionary value type 'NSNumber'. _ = NSLayoutConstraint.constraints(withVisualFormat: |[v1(a)]|, metrics: [a: a], views: [v1: v1]) let met = [a: a] // 3: This fails with Cannot convert value of type '[String: Int]' to expected argument type '[String: NSNumber]?'. _ = NSLayoutConstraint.constraints(withVisualFormat: |[v1(a)]|, metrics: met, views: [v1: v1]) // 4: This compiles. _ = NSLayoutConstraint.constraints(withVisualFormat: |[v1(a)]|, metrics: met as [String: NSNumber]?, views: [v1: v1]) // 5: This fails with Cannot convert value of type 'Int' to expected dictionary value type 'NSNumber'. _ = NSLayoutConstraint.constraints(withVisualFormat: |[v1(a)]|, metrics: [a: a] as [Stri
11
0
2.2k
Aug ’16
Reply to SwiftUI internal crash when interacting with long list quickly
Hello thanks for your help in investigating this. Additional context here is that our application is Swift 6, SwiftUI only. The min deployment target was set at 17.0 and we only started witnessing this crash for iOS devices on 18.4+. I reviewed the documentation for debugging techniques linked. I believe the most relevant common crash referenced is a language exception. I verified that I have at least a partially symbolicated crash report via the presence of function names. Its hard to 100% confirm if it is a partial vs fully symbolicated as all the frames included in the crash are low level library/internal apple frameworks and I am not sure how much is supposed to be exposed. Some additional nuggets here is that the application is distributed via enterprise (so no crashes support in Xcode organizer / App Store Connect) and the crash is not easily reproduced (3 occurrences within the past 2 1/2 weeks). The steps list here to import a crash to the Devices and Simulators do not look to allow for drag
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’25
Reply to "Passing argument of non-sendable type 'ContentView' outside of main actor-isolated context may introduce data races"
I’m confused. I pasted your code into a new project (details below) and I didn’t see the errors you described. And, looking at that code, I wouldn’t expected to see errors in Xcode 16 beta because doingSomeAsyncWork() is a main-actor-isolated method. Here’s my specific test: Using Xcode 16.0b4, I created a new project from the macOS > App template. I replaced ContentView with your code. And added an import MusicKit to the top. The code builds without any warnings. I then changed the target to use the Swift 6 language mode; it continues to build. An a more theoretical level, the reason why doingSomeAsyncWork() is main-actor-isolated is due to a change in SwiftUI in Xcode 16 beta. Historically only the body property of View was main-actor-isolated. Now the entire View protocol is, which means all methods and properties on ContentView are main-actor-isolated unless you opt out using nonisolated. Also, you wrote this: Marking @MainActor is not an option since some of these functions might be running f
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’24
Sending main actor-isolated value of type 'PurchaseAction' with later accesses to nonisolated context risks causing data races
Trying to migrate to Swift 6. However getting this error when using SwiftUI StoreKit purchase environment. Sending main actor-isolated value of type 'PurchaseAction' with later accesses to nonisolated context risks causing data races @Environment(.purchase) private var purchase let result = try await purchase(product)
1
0
757
Sep ’24
Why works on swift 2 beta 1 not on beta 6
I'm using this piece of code to access a url with beta 1 let config = NSURLSessionConfiguration.defaultSessionConfiguration() let userPasswordString = hroman:javierA17 let userPasswordData = userPasswordString.dataUsingEncoding(NSUTF8StringEncoding) let base64EncodedCredential = userPasswordData!.base64EncodedStringWithOptions(nil) let authString = Basic (base64EncodedCredential) config.HTTPAdditionalHeaders = [Authorization : authString] let session = NSURLSession(configuration: config) var running = false let url = NSURL(string: http:/ let task = session.dataTaskWithURL(url!) { (let data, let response, let error) in if let httpResponse = response as? NSHTTPURLResponse { let dataString = NSString(data: data!, encoding: NSUTF8StringEncoding) print(dataString) } running = false } running = true task.resume() while running { print(waiting...) sleep(1) }I changed a few things and it doesn't work let config = NSURLSessionConfiguration.defaultSessionConfiguration() let userPasswordString = hroman:javierA17 let use
10
0
1.2k
Sep ’15
Reply to Swift 3 or 4
Thank you OOPer, I’m new to this. Basically what I mean is, if I make an app for iPhone 5 with Swift 3 and would like to make the SAME app for iPhone 6 with Swift 4. Can I make the app in both phones with one swift. Including iPhone 4,5,6,7,8,10 etc.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’18
Xcode 16 Beta 3: "Cannot expand accessors on variable declared with 'let'"
Running into this new issue in beta 3. All of our immutable model attributes are now triggering swift compiler error from the title (tied to swift 6 - warning in swift 5). Neither warning or error show up on previous builds. Anyone else running into this? Hopefully not a limitation on swiftData that attributes must be mutable? filed as: FB14379932 (new in Xcode 16 beta3: cannot expand accessors on variable declared with 'let' in SwiftData Models)
5
0
2.6k
Jul ’24
Reply to Swift 6 Migration error in Sample code (Updating an app to use strict concurrency sample code) provided by Apple.
Just so we’re clear, we’re talking about the Updating an app to use strict concurrency sample code which is associated with WWDC 2024 Session 10169 Migrate your app to Swift 6. When I build that with Xcode 16.0 I see the error you’re reporting. I think Xcode is correct here, and the sample is in error. To explore this, I hacked up the code to look like this: private func queryHealthKit2() async throws -> HKSample { try await withCheckedThrowingContinuation { continuation in … unchanged … // 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 { let s = samples!.first! continuation.resume(returning: s) // ^ Sending 's' risks causing data races // task-isolated 's' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses } } s
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’24