Swift Concurrency by Example 第2页
How to test AsyncSequence and AsyncStream 如何测试 AsyncSequence 和 AsyncStream-Stewed Noodles 资源

How to test AsyncSequence and AsyncStream 如何测试 AsyncSequence 和 AsyncStream

Concurrent Swift code often streams values over time rather than returning them all at once, so it's important to be able to write tests to check an AsyncStream, AsyncSeq...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
50
How to test completion handlers with Swift Testing and XCTest 如何使用 Swift Testing 和 XCTest 测试补全处理程序-Stewed Noodles 资源

How to test completion handlers with Swift Testing and XCTest 如何使用 Swift Testing 和 XCTest 测试补全处理程序

When you're dealing with older concurrency code that relies on callback functions that get run when some work completes rather than using Swift concurrency's async/await ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
10
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 资源烩之面大会员jiulinxiri5个月前
70
Introduction to testing Swift concurrency Swift 并发测试简介-Stewed Noodles 资源

Introduction to testing Swift concurrency Swift 并发测试简介

Swift's full range of concurrency features work great with unit tests using both the legacy XCTest framework and the new Swift Testing framework.Swift 的全套并发功能非常适合使用旧...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
50
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 资源烩之面大会员jiulinxiri5个月前
70
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 资源烩之面大会员jiulinxiri5个月前
90
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 资源烩之面大会员jiulinxiri5个月前
80
What is actor hopping and how can it cause problems? 什么是 actor 跳转,它如何导致问题?-Stewed Noodles 资源

What is actor hopping and how can it cause problems? 什么是 actor 跳转,它如何导致问题?

When a thread pauses work on one actor to start work on another actor instead, we call it actor hopping, and it will happen any time one actor calls another.当线程暂停对一个 a...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
60
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 资源烩之面大会员jiulinxiri5个月前
100
Who decides which actor code runs on? 谁决定在哪个 actor 代码上运行?-Stewed Noodles 资源

Who decides which actor code runs on? 谁决定在哪个 actor 代码上运行?

One common confusion with actors comes in deciding exactly where code runs, because just adding @MainActor and hoping for the best is rarely good enough.与 Actor 的一个常...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
80