Struct
구조체 : 일종의 class, 재사용성을 위해 사용
ex)
struct UserInfo {
let name:String
let age :Int?
let email :String?
let job : String?
let hasPet : Bool
func sayMyName(with name : String) {
print(name)
}
}
...
VStack{
Text(userinfo.name)
Text(userinfo.age?.description ?? "100")
Text(userinfo.email?.description ?? "test@test.com")
Text(userinfo.job?.description ?? "no")
Text(userinfo.hasPet.description)
Button {
userinfo.sayMyName(with : userinfo.name)
} label: {
Text("Button")
}
}
...
let Sejun = UserInfo(name: "세준", age: 25, email: "leesjun29@gmail.com",
job: "Student", hasPet: false)
MyStruct(userinfo:Sejun )
결과