370 questions
-1
votes
0
answers
20
views
Crash when calling WKHTTPCookieStore.setCookie in async function
I’m running into a crash when trying to sync cookies from my app to a WKWebView’s HTTPCookieStore. The crash happens at the setCookie call inside an async function. I’m not sure why it’s happening.
...
-1
votes
1
answer
47
views
Swift Observation + AsyncStream: value updates lag one cycle behind termination state change [closed]
I’m using Swift’s new Observation framework to create an AsyncStream that reacts to changes in an observable object. The stream should emit new values whenever a tracked property changes and ...
1
vote
1
answer
61
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 ...
1
vote
1
answer
89
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 ...
0
votes
0
answers
92
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 ...
0
votes
0
answers
44
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.
...
-1
votes
1
answer
150
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 ...
1
vote
1
answer
317
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 ‘...
1
vote
1
answer
109
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 ...
1
vote
2
answers
120
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 ...
1
vote
1
answer
240
views
Passing closure risks causing data races
I know this sort of thing has been asked and answered before — see, for example, Swift 6 warnings "Passing closure as a 'sending' parameter risks causing data races" — but I still ...
0
votes
0
answers
71
views
Conforming to protocol and Swift Concurrency Errors approach
Trying to adapt to the Protocol generated from Kotlin Multiplatorm in Objective-C exposed to Swift. I'm learning Swift Concurrency and I'm not sure how to approach to this.
Basically this protocol ...
0
votes
1
answer
58
views
Call to actor-isolated instance in extension for 3rd party actor
I'm migrating to Swift 6 and in the same time I'm trying to learn Swift Concurrency. I have the following code with the exception. I would like to understand the problem and learn how to solve this ...
3
votes
2
answers
136
views
can't implement UIView `description` because it isn't MainActor
Let the code speak for itself:
final class Piece: UIView {
var picName: String
var column: Int
var row: Int
override var description: String {
return "picname: \(picName);...
1
vote
2
answers
77
views
How does the Xcode 's document knows my custom view is a MainActor
CityView is a custom View in a demo project , But the Xcode's documents says it was a @MainActor , and CityView isn't defined as @MainActor in project .
How does the Xcode's help document knows it was ...
1
vote
1
answer
95
views
Unexpected Concurrency Error in Swift TaskGroup
The Swift 6 compiler emits the following error
Sending value of non-Sendable type '() async throws -> ()' risks causing data races
when explicitly specifying an actor as the isolation for the ...
0
votes
1
answer
143
views
Swift - concurrent data access - fast main thread reads (stale OK) & background writes
I'm working on a Swift application where I need to manage a piece of data (e.g., a CGRect representing a rectangle's position) that can be modified on a background thread/task, while concurrently ...
2
votes
1
answer
138
views
With Swift Concurrency, is there a way to define a shared actor used across multiple classes, like MainActor?
Is there a mechanism, like the @MainActor tag, where we can specify a shared non-main thread that designated classes are on?
I would like to be able to setup something like:
@AnimalsActor
final class ...
1
vote
1
answer
452
views
How to convert async function/method to publisher in Swift 6
I tried to make as simple example as possible using Swift 6 to produce this problem which I am having difficulty to solve:
func getValue() async -> Int { 0 }
func getValuePublisher() -> ...
-2
votes
2
answers
292
views
Is Task.detached a good and correct way to offload heavy work from the UI thread to keep the UI smooth?
I have two use cases: offloading heavy work from the UI thread to keep the UI smooth.
Perform searching while user is typing.
extension MoveNoteViewController: UISearchBarDelegate {
// Busy ...
0
votes
1
answer
73
views
Observing voiceover changes on Mac - Swift 6 migration issues
I am listening to voiceover changes through NSWorkspace KVO and here is my code
public final class MyContext: ObservableObject {
public weak var actionHandler: ActionHandler?
public weak var ...
2
votes
2
answers
563
views
Task-isolated 'result' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses
I have this code below and the compiler throws me an error at line "continuation.resume(returning: result)", saying "sending result risks causing data races"
How can I fix this?
I ...
2
votes
1
answer
294
views
Why does a @MainActor nonisolated property accessing a @MainActor protocol’s nonisolated property produce a warning?
I’m encountering an error when mixing @MainActor and nonisolated, particularly when a @MainActor nonisolated property accesses a nonisolated property from a @MainActor protocol. The code is
Example 1
@...
0
votes
1
answer
140
views
Local vs Global Actors in Observable Model Objects
I have the following SwiftUI Observable model class along with a local & global actor variables that fails to build with the error Global actor 'MyGlobalActor'-isolated default value in a ...
-1
votes
2
answers
93
views
Actors conformance to Protocols
What is the rationale behind Swift compiler being overly strict about Protocol conformances? For instance, consider the following code:
protocol TestProtocol {
func testFunction()
}
actor ...