[swift] 51. struct 기본 생성자

RudinP·2023년 10월 20일
0

Study

목록 보기
70/227
  • struct에서는 기본적으로 생성자가 탑재되어있다.
  • 따로 struct 내에 생성자를 정의하는것도 ok
  • extension을 이용하여 여러 버전의 생성자를 정의할 수도 있다.
struct Pet{
	var name: String
}

let pet = Pet(name: "댕댕이")

extension Pet{
	init(){
    	name = "야옹이"
    }
}

let cat = Pet() //야옹이
profile
곰을 좋아합니다. <a href = "https://github.com/RudinP">github</a>

0개의 댓글