最新发布第11页
排序
语法(三) – guard
guard 语句的主要用法有以下几种: 提前返回 减少缩进级别 高Happy Path可见性 提前返回 guard 用于提前返回,如果某些先决条件未满足,则退出函数。 func giveAward(to name: String) { guard n...
如何在 SwiftUI 预览中使用 SwiftData
基于模型扩展在模型的基础上进行扩展,这里以 movie 模型为例import Foundation import SwiftData @Model final class Movie { var title: String var year: Int @Relationship(deleteRule: .ca...
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...
Day 19 – 实例、状态和高级函数
事件监听 turtle模块的事件监听,通过 screen 的 listen 方法实现。 from turtle import Turtle, Screen tim = Turtle() screen = Screen() def move_forward(): tim.forward(100) # 监听屏幕输...
插入数据
在SwiftData 中插入数据非常简单,默认情况下数据会自动保存,无需手动调用保存操作。以下示例演示了如何创建一个 Student 模型并插入一条记录,数据将自动保存: @Model class Student { var n...
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...
物资、设备与资产
采购阶段 在采购阶段设备以物资的形式呈现,采购阶段主要是物资的采购、到货以及验收。物资形式下的设备拥有物资编码。 设备建档 物资采购完成后,可以进行设备建档,设备建档会生成设备编码。 ...
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...
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...
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...




