Questions tagged [swift-concurrency]

For concurrency language features in Swift, such as async and await. This tag also includes other concurrency features such as actors, Sendable closures, and more.

Swift concurrency with async-await can allow for more readable asynchronous code, an improvement over traditional completion handler closure patterns. “Swift concurrency” also include “actors” (a new object type designed to avoid data races), “tasks” (an object that wraps an asynchronous task, often useful for launching asynchronous action from synchronous context, managing dependencies, or when implementing cancelation support), “sendable” types, etc.

Swift concurrency was introduced in Swift 5.5 in Xcode 13 (supporting macOS 12 and iOS 15), but Xcode 13.3 introduced some backward-compatibility with recent OS versions (e.g., back to iOS 13).

Swift concurrency offers mechanism to retire completion handler closure patterns. In many cases, it obviates the need for code written for and .

References

200 questions
0
votes
1 answer

MainActor.run failing to run closure when called from within a detached task

I have encountered an issue when trying to update the status of a detached task, by passing a closure to MainActor.run. To illustrate the issue consider a function that counts the number of files in a folder and its sub-directories. It runs in a…
Philip Pegden
  • 1,732
  • 1
  • 14
  • 33
-1
votes
1 answer

Is there a way to force foo2() to be executed after foo1() without modifying foo1() - Swift

How can the following code be modified to print 2 after 1, without modifying the foo1() function? func foo1() { Task { try await Task.sleep(nanoseconds: 1_000_000_000) print("1") } } func foo2() { print("2") } func…
-2
votes
1 answer

Swift 5.8 + iOS 14.0?

I work on a suite of internal libraries that are distributed via Cocoapods. Our current minimum deployment version is 14.0. We've got the Podspec for each library setting the Swift version to 5.3, which was the version that shipped with Xcode 12.0,…
Joshua Sullivan
  • 1,073
  • 8
  • 12
-2
votes
1 answer

Awaiting Task Completion in SwiftUI View

I am working with a view that displays a list of locations. When a user taps on a location, a didSet block containing a Task is triggered in a separate class wrapped with the @ObservedObject property: struct LocationSearch: View { @StateObject…
John Harrington
  • 1,314
  • 12
  • 36
-5
votes
2 answers

Swiftui async / await with Firebase

I am trying to get the last AppVersion dokument out from the database! What am I doing wrong here? func getLastAppVertion() async throws -> ApplicationVersion { firebase.collection("ApplicationVersion") .order(by:…
Turbojens
  • 9
  • 3
1 2 3
13
14