最新发布第29页
排序
@Transient 宏忽略属性持久化
如果你的模型类有一个或多个存储属性,希望在写入持久化存储时忽略一些属性,可以使用 @Transient 宏进行标注,这样 SwiftData 就不会将它们的值写入磁盘。 默认情况下,SwiftData 会将所有计算...
关系最大最小约束
SwiftData 的 @Relationship 宏允许我们指定一对多或多对多连接中应存在的最小和最大对象数量。 超出这些限制时,SwiftData 的自动保存将静默失败,可能导致数据丢失,除非及时进行纠正。 例如...
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...
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 ...
SwiftData 何时保存数据
SwiftData 会立即自动有效地保存所有更改,它是如此之快,以至于任何数据丢失的可能性实际上为零。具体的保存场景: 每次应用程序进入后台 每次应用程序回到前台 每次当前 runloop 结束时


