行业知识
Swift SwiftUI 学习笔记 2024
2026-11-12 08:48:26
来源:互联网转载
Swift SwiftUI 学习笔记 2024
一、资源
视频资��� StanfordUnivercity 公开课 2023: https://cs193p.sites.stanford.edu/2023
教程 Swift 初识:基础语法:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/
二、Playground
如何打开 playground?
找到 File -> New -> PlayGround
三、class 与 struct 的区别
- struct 是值类型的变量,传递的时候传递的是值的复制值
- class 是引用型变量,传递的时候传递的是它的引用
- class 需要 init 方法进行初始化, struct 则不需要,默认就对内部的变量进行 init 操作,可以说是免 init
- struct 内的所有变量都必须有默认值
struct 写法,简写
RoundedRectangle(cornerRadius: 20)RoundedRectangle(cornerRadius: 20).fill()
VStack { CardView(isFaceUp: true) CardView() CardView() CardView(isFaceUp: true)}VStack() { CardView(isFaceUp: true) CardView() CardView() CardView(isFaceUp: true)}VStack{}.onTapGesture(perform: { print("tapped")})// ===VStack{}.onTapGesture { print("tapped")}struct 特性
如果想改变 struct 内的变量,如果方法要改变值,需要添加 matable
struct 只有一条指令时,不需要使用 return
四、 一些知识
Bool 有 .toggle 方法
func toString(by offset: Int, label: String) -> some View {// by 是外部变量名 offset 是内部使用的变量名}
上一篇:服务器怎么关机手动重启?
下一篇:E站下载教程,轻松获取所需内容