type property

권현석·2023년 1월 20일
0
struct Mystructure {
	let instanceProperty = "ABC"
    static let typeProperty = "123"
}
let myStructure = Mystructure()
print(myStructure.instanceProperty) // ABC
print(Mystructure.typeProperty) // 123
  • instace property: class 또는 structure에 상수 또는 변수로 만들어진 property
  • type property: instance property 앞에 'static'을 붙여줌으로써 instace property를 type property로 바꿈
  • type property의 경우 structure에 있는 새로운 instance 객체를 만들 필요가 없이 structure를 통해 바로 property를 불러올 수 있다.

즉, type property는 type(structure와 class는 data type으로 취급)과 관련있고, instance property는 type(여기서는 structure, class)에서 만들어진 instance와 관련이 있다.

이는 property 뿐만 아니라 메서드에서도 적용된다.

profile
wanna be an iOS developer

0개의 댓글