366 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
1
answer
96
views
Swift/objc interoperability and modern swift concurrency
How to resolve error:
Non-Sendable parameter type BookInfo of actor-isolated @objc instance method cannot cross actor boundary?
BookStore.swift:
// manage state of instances of BookInfo
@objc actor ...
1
vote
1
answer
62
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 ...
0
votes
0
answers
65
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: ...
1
vote
1
answer
94
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
61
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 ...
0
votes
0
answers
108
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 ...
3
votes
1
answer
244
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
...
0
votes
1
answer
138
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
...
-1
votes
1
answer
172
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 ...
2
votes
3
answers
411
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 {
...
1
vote
1
answer
413
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 ‘...
2
votes
1
answer
73
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.
...
1
vote
1
answer
120
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
votes
1
answer
88
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 ...
1
vote
2
answers
127
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 ...