Skip to main content
1 vote
1 answer
51 views

Why does wrapping `continuation.resume(with:)` in a closure resolve this warning?

When writing new async/await code that makes use of an existing completion-based service, I've found it is necessary to wrap the call to continuation.resume(with:) in what feels like a redundant ...
Chris's user avatar
  • 3,879
0 votes
0 answers
53 views

How can I mutate a MainActor ‑isolated property from a Sendable closure I don’t control in Swift concurrency?

I’m migrating an OAuth sign‑in feature to Swift 6. The view model stores the discovery configuration as a @MainActor property: @Observable class AuthModel { @MainActor var configuration: ...
Ronika Kashyap's user avatar
1 vote
1 answer
71 views

Swift 6 Strict Concurrency accessing C shared instance

I am trying to adapt C code, measuring pre/after main time, so it could be accessed from Swift with SC on. But nothing can silent compiler warning, indicating this code is not safe. I've tried every ...
JuicyFruit's user avatar
  • 2,690
0 votes
0 answers
60 views

Why does Swift require nonisolated for a pure String extension? [duplicate]

I extended String with a pure function that copies a prefix of up to maxLength characters. The code below produces a build error: Call to main actor-isolated instance method 'copiedPrefix' in a ...
Erik's user avatar
  • 2,148
0 votes
0 answers
74 views

How to mutate a Main actor-isolated property from a Sendable closure that I do not control?

For authentication in my Swift 6 app I use the AppAuth library. One of the steps in authenticating a user involves fetching the OIDC configuration. The library offers a way to do so which involves a ...
Pieter's user avatar
  • 263
3 votes
1 answer
190 views

Swift Concurrency: error vs warning when accessing main actor-isolated function in closure

Consider following code: class MyViewController: UIViewController { var callback: (() -> Void)? func setCallback(_ callback: (() -> Void)?) { self.callback = callback ...
Varrry's user avatar
  • 2,777
0 votes
0 answers
40 views

Swift 6: “Main actor-isolated conformance of FeelingType to Encodable cannot be used in nonisolated context” with SwiftData @Model [duplicate]

I’m migrating a small SwiftData model from Swift 5 to Swift 6. The same code compiles under Swift 5, but with Swift 6 it fails when the @Model macro expands a property whose type conforms to Codable. ...
markb's user avatar
  • 1,369
0 votes
1 answer
112 views

Access to MainActor context in blocking way from nonisolated method

I have such protocol not owned by my codebase. It came from library. I extracted it to bare minimum just to focus on one problem. protocol BatteryLevelProvider { func getBatteryLevel() -> Float ...
Marcin Kapusta's user avatar
-1 votes
1 answer
139 views

Implementing Combine map operator that read data from MainActor

I have a feeling that Swift Concurrency is fighting agains me all the time. It is really frustrating. My problem. I need to create Combine publisher to emit battery state on iOS device. So far I have ...
Marcin Kapusta's user avatar
2 votes
3 answers
291 views

How to unit test AsyncStream functionality

I have a simple view model like this: import Foundation import SwiftUI typealias MessagePollResult = Result<[Message], Error> @MainActor final class ChatScreenViewModel: ObservableObject { ...
Bawenang Rukmoko Pardian Putra's user avatar
1 vote
1 answer
221 views

Capturing a @MainActor-isolated method reference into a SwiftUI view’s escaping closure still triggers “isolated → non-isolated” error

I have two SwiftUI views and a @MainActor protocol for handling navigation events. I’m trying to pass a method reference directly into an escaping closure, but the compiler complains: Task-isolated ‘...
user2037296's user avatar
2 votes
1 answer
64 views

Mutating actor state in the nonisolated method required by protocol

How Actor can Conform to protocol and mutate its internal state in nonisolated method that is required by this protocol. There is no write access in nonisolated method to isolated property by actor. ...
Marcin Kapusta's user avatar
1 vote
1 answer
102 views

RxSwift's Signal equivalent in Combine / Concurrency

I have been using RxSwift for my apps before Combine, Swift Concurrency and SwiftUI. In RxSwift we can have a Signal that will just emit without replaying the previous value which is very useful to ...
Bawenang Rukmoko Pardian Putra's user avatar
-1 votes
1 answer
60 views

Wait for Task to finish in XCTest without using Task.sleep

I have following case. NotMyProtocol is from external library. It is not suitable to work with Swift Concurrency so I though some way to implement it and I will pass some proxy into it to forward ...
Marcin Kapusta's user avatar
1 vote
2 answers
111 views

How to pass a function returning `some View` as parameter to `sheet(item:onDismiss:content:)`

I am using the modifier sheet(item:onDismiss:content:) to show a sheet, where the content of the sheet depends on the item that is passed as parameter. The body of the sheet is built using a function ...
Benzy Neez's user avatar
  • 28.7k

15 30 50 per page
1
2 3 4 5
25