Day 2 – 理解数据类型和字符串操作
基本数据类型 String 字符串下标 字符串的下标 Subscripting可以提取字符串特定位置的字符。 # 提取第一个字符 print('Hello'[0]) # H # 提取最后一个字符 print('Hello'[len('Hello') - 1]) # ...
Day 5 – 循环
for 循环 for 循环的基本语法,如下所示 for item in list_of_items: # do something to each item 示例代码 fruits = ['Apple', 'Peach', 'Pear'] for fruit in fruits: print(fruit) # Apple ...
Day 11 – 21点(黑杰克)
游戏介绍 黑杰克(英语:Blackjack),是使用扑克牌玩的赌博游戏。游戏目标是将选手的卡片计数添加到最大而不超过21。纸牌的计数规则:A可作1或11点,2-10作该牌之点数,J、Q、K作10点。 代码实...
ScrollViewReader
Scroll View Reader 让你可以访问一个名为 scrollTo 的函数。通过这个函数,你可以通过自动滚动使滚动视图中的某个视图可见。 介绍 使用 ScrollViewReader 访问 scrollTo 函数,以便以编程方式...
@Transient 宏忽略属性持久化
如果你的模型类有一个或多个存储属性,希望在写入持久化存储时忽略一些属性,可以使用 @Transient 宏进行标注,这样 SwiftData 就不会将它们的值写入磁盘。 默认情况下,SwiftData 会将所有计算...
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 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 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...