Swift Concurrency by Example共61篇
How to make function parameters isolated 如何隔离函数参数-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
400
What is an asynchronous function?什么是异步函数?-Stewed Noodles 资源

What is an asynchronous function?什么是异步函数?

Although Swift functions are synchronous by default, we can make them asynchronous by adding one keyword: async. Inside asynchronous functions, we can call other asy...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
270
How to use @MainActor to run code on the main queue 如何使用 @MainActor 在主队列上运行代码-Stewed Noodles 资源

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)...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
270
How to create and use an actor in Swift 如何在 Swift 中创建和使用 actor-Stewed Noodles 资源

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 ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
260
How to create and run a task 如何创建和运行任务-Stewed Noodles 资源

How to create and run a task 如何创建和运行任务

Swift’s Task struct lets us start running some work immediately, and optionally wait for the result to be returned. And it is optional: sometimes you don’t ca...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
0250
Understanding how priority escalation works 了解优先级提升的工作原理-Stewed Noodles 资源

Understanding how priority escalation works 了解优先级提升的工作原理

Every task can be created with a specific priority level, or it can inherit a priority from somewhere else. But in two specific circumstances, Swift will raise the priori...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
230
How to write basic async tests 如何编写基本的异步测试-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
210
How to get a Result from a task 如何从任务中获取 Result-Stewed Noodles 资源

How to get a Result from a task 如何从任务中获取 Result

If you want to read the return value from a Task directly, you should read its value using await, or use try await if it has a throwing operation...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
210
How to download JSON from the internet and decode it into any Codable type 如何从 Internet 下载 JSON 并将其解码为任何 Codable 类型-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
200
What is actor reentrancy and how can it cause problems? 什么是 actor 重入性,它如何导致问题?-Stewed Noodles 资源

What is actor reentrancy and how can it cause problems? 什么是 actor 重入性,它如何导致问题?

Actor-isolated functions are reentrant, which means it's possible for one piece of work to begin before a previous piece of work completes. This opens the possibility of subtle bug...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
200