구조체 프로퍼티 및 메소드
- 프로퍼티는 cpp에서의 멤버변수, java에서의 필드와 비슷한 개념이다.
- 메소드는 cpp에서의 멤버함수, java에서 메소드와 비슷한 개념이다.
struct Sample{
var mutableProperty: Int = 100
let imutableProperty : Int = 100
static var typeProperty : Int = 100
func instanceMethod(){
print("instanceMethod()")
}
static func typeMethod(){
print("typeMethod()")
}
}
구조체 사용
var mutable : Sample = Sample()
mutable.mutableProperty = 200
mutable.immutableProperty = 200
let immutable : Sample = Sample()
immutable.mutableProperty = 200
immutable.immutableProperty = 200
Sample.typeProperty = 200
Sample.typeMethod()
mutable.typeProperty = 200
mutable.typeMethod()