Swift

[Swift] 10. 구조체

CodingKwon 2021. 10. 6. 23:04

1. 구조체

  • 구조체는 값 타입
  • 타입은 대문자 카멜케이스를 사용하여 정의
struct 이름 {
	/* 구현부 */
}

 

struct Sample {
	// 가변 프로퍼티
    var mutableProperty: Int = 100 
    
    // 불변 프로퍼티
    let immutableProperty: Int = 100 
    
    // 타입 프로퍼티
    static var typeProperty: Int = 100 
    
    // 인스턴스 메서드
    func instanceMethod() {
        print("instance method")
    }
    
    // 타입 메서드
    static func typeMethod() {
        print("type method")
    }
}