Swift Concurrency by Example 第3页
How to handle concurrency errors in unit tests 如何处理单元测试中的并发错误-Stewed Noodles 资源

How to handle concurrency errors in unit tests 如何处理单元测试中的并发错误

Both Swift Testing and XCTest give us three main options for handling errors in tests: we can consider them immediate failures, we can handle them internally and make our own asser...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
160
How to loop over an AsyncSequence using for await 如何使用 for await 遍历 AsyncSequence-Stewed Noodles 资源

How to loop over an AsyncSequence using for await 如何使用 for await 遍历 AsyncSequence

You can loop over an AsyncSequence using Swift’s regular loop types, for, while, and repeat, but whenever you read a value from the async sequence you mus...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
160
How to store continuations to be resumed later 如何存储要稍后恢复的 continuations-Stewed Noodles 资源

How to store continuations to be resumed later 如何存储要稍后恢复的 continuations

Many of Apple’s frameworks report back success or failure using multiple different delegate callback methods rather than completion handlers, which means a simple continuation won...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
160
How to convert an AsyncSequence into a Sequence 如何将 AsyncSequence 转换为 Sequence-Stewed Noodles 资源

How to convert an AsyncSequence into a Sequence 如何将 AsyncSequence 转换为 Sequence

Swift does not provide a built-in way of converting an AsyncSequence into a regular Sequence, but often you’ll want to make this conversion yourself so you don’t n...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
160
What’s the difference between actors, classes, and structs? Actors、Classes和 Structs 之间有什么区别?-Stewed Noodles 资源

What’s the difference between actors, classes, and structs? Actors、Classes和 Structs 之间有什么区别?

Swift provides four concrete nominal types for defining custom objects: actors, classes, structs, and enums. Each of these works a little differently from the others, but the first...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
150
How to discard results in a task group 如何丢弃任务组中的结果-Stewed Noodles 资源

How to discard results in a task group 如何丢弃任务组中的结果

Swift has a special task group type called a discarding task group, which has a very specialized function: tasks that complete are automatically discarded and destroyed, ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
150
What is a synchronous function? 什么是同步函数?-Stewed Noodles 资源

What is a synchronous function? 什么是同步函数?

By default, all Swift functions are synchronous, but what does that mean? A synchronous function is one that executes all its work in a simple, straight line on a single threa...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
0150
Understanding how global actor inference works 了解全局参与者推理的工作原理-Stewed Noodles 资源

Understanding how global actor inference works 了解全局参与者推理的工作原理

Apple explicitly annotates many of its types as being @MainActor, including most UIKit types such as UIView and UIButton. However, for a while the Swift team da...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
140
How to create and use AsyncStreams to return buffered data 如何创建和使用 AsyncStreams 返回缓冲数据-Stewed Noodles 资源

How to create and use AsyncStreams to return buffered data 如何创建和使用 AsyncStreams 返回缓冲数据

AsyncStream and AsyncThrowingStream can be thought of a bit like continuations that can send back multiple values, but also like an AsyncSequence that is a...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
130
Important: Do not use an actor for your SwiftUI data models 重要提示:请勿将角色用于 SwiftUI 数据模型-Stewed Noodles 资源

Important: Do not use an actor for your SwiftUI data models 重要提示:请勿将角色用于 SwiftUI 数据模型

Swift’s actors allow us to share data in multiple parts of our app without causing problems with concurrency, because they automatically ensure two pieces of code cannot...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
130