排序
Swift Concurrency by Example
Async/await Sequences and streams Tasks and task groups Actors Testing Solutions
How to use @MainActor to run code on the main queue 如何使用 @MainActor 在主队列上运行代码
@MainActor is a global actor that uses the main queue for executing its work. In practice, this means methods or types marked with @MainActor can (for the most part)...
How to make function parameters isolated 如何隔离函数参数
Any properties and methods that belong to an actor are isolated to that actor, but you can make external functions isolated to an actor if you want. This allows the funct...
How to create and use an actor in Swift 如何在 Swift 中创建和使用 actor
Creating and using an actor in Swift takes two steps: create the type using actor rather than class or struct, then use await when accessing its ...
What is an actor and why does Swift have them? 什么是 actor,为什么 Swift 有它们?
Swift’s actors are conceptually like classes that are safe to use in concurrent environments. This safety is made possible because Swift automatically ensures no two pieces of cod...
How to write basic async tests 如何编写基本的异步测试
Both Swift Testing and XCTest allow us to test asynchronous code built with Swift concurrency by marking tests as async. This means we can wait for concurrent code to complete...
How to download JSON from the internet and decode it into any Codable type 如何从 Internet 下载 JSON 并将其解码为任何 Codable 类型
Fetching JSON from the network and using Codable to convert it into native Swift objects is probably the most common task for any Swift developer, usually followed by dis...
How to serialize parameterized tests with Swift Testing 如何使用 Swift Testing 序列化参数化测试
Swift Testing's parameterized tests allow us to send multiple values into a single test, and they'll be run in parallel for maximum performance. If you don't want this – if you wa...
How to force concurrent tests to run on a specific actor 如何强制并发测试在特定actor上运行
Swift Testing and XCTest behave differently when it comes to running tests in parallel: unless you say otherwise, Swift Testing will run both synchronous and asynchronous tests on ...
How to set a time limit for concurrent tests 如何为并发测试设置时间限制
Both Swift Testing and XCTest have simple mechanisms for controlling how long tests should be allowed to run before being considered a failure. This is critically important for con...