排序
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...
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...
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...
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 run tasks using SwiftUI’s task() modifier 如何使用 SwiftUI 的 task() 修饰符运行任务
SwiftUI provides a task() modifier that starts a new task as soon as a view appears, and automatically cancels the task when the view disappears. This is sort of the equi...
How to create a task group and add tasks to it 如何创建任务组并向其添加任务
Swift’s task groups are collections of tasks that work together to produce a single result. Each task inside the group must return the same kind of data, but if you use enum assoc...
How to use continuations to convert completion handlers into async functions 如何使用 continuations 将完成处理程序转换为异步函数
Older Swift code uses completion handlers for notifying us when some work has completed, and sooner or later you’re going to have to use it from an async function –&nbs...
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 create continuations that can throw errors 如何创建可以抛出错误的continuations
Swift provides withCheckedContinuation() and withUnsafeContinuation() to let us create continuations that can’t throw errors, but if the API you’re using ...
Sending data safely across actor boundaries 跨参与者边界安全地发送数据
Swift tries to ensure access to shared data is done safely, partly through types such as actors, and partly through a concept of sendability implemented through the ...