最新发布第27页
排序
多对多关系
在SwiftData 中,当关系的双方都使用数组时,就会创建多对多关系。这类关系相当常见,比如:一个老师有多个学生,一个学生可以有多个老师;一个演员参演了多部电影,一部电影也有许多演员参与;...
更新数据
在 SwiftData 中更新数据非常简单,默认情况会自动保存,无需手动调用保存操作。以下示例演示了创建一个 Student模型,并获取模型的数据进行更新,数据将自动保存: @Model class Student { var...
withAnimation
使用提供的动画重新计算视图主体,并返回结果。 struct ContentView: View { @State private var isActive = false var body: some View { VStack(alignment: isActive ? .trailing : .leading)...
How to create and use async properties 如何创建和使用异步属性
Just as Swift’s functions can be asynchronous, computed properties can also be asynchronous: attempting to access them must also use await or similar, and may also need&...
How to call an async function using async let 如何使用 async let 调用 async 函数
Sometimes you want to run several async operations at the same time then wait for their results to come back, and the easiest way to do that is with async let. This lets you start...
Why can’t we call async functions using async var? 为什么我们不能使用 async var 调用 async 函数?
Swift’s async let syntax provides short, helpful syntax for running lots of work concurrently, allowing us to wait for them all later on. However, it only works as ...
RecyclerView
RecyclerView 是 Android 中一个用于高效展示大量列表数据的强大控件,是 ListView 的升级版。它具有更好的性能、更灵活的布局管理方式,并且支持强大的扩展能力。 RecyclerView 会回收这些独立...
Class
带构造函数的类 /** * 带构造函数的类 */ class Robot(val name: String) { fun greetHuman() { println('Hello human, my name is $name') } fun walk() { println('I'm walking') } } // 类对...
Data Class 数据类
Kotlin 中的 数据类(data class) 是一种用于只存数据的类,能够自动生成常用的函数。 equals() hashCode() toString() copy() 语法 data class ClassName( val prop: Type, var prop2: Type )...





