Methods는 함수. Classes, structures, and enumeratiosn 는 instance mothods를 부를 수 있어. 그리고 이것은 특정한 일과 함수를 캡슐화할 수 있어. 또한, 저것들은 class methods를 정의 할 수 있어.
Instance Methods
Instance methods는 말그대로 instance에 속한 class, structure, and enumeration이야.
Instanced의 예시
The self Property
모든 instance의 type은 함축적인 properties를 가짐. self.라고 불리는 이것은 정확히 instance 그자체와 같다.
self를 굳이 사용할 필요는 없데, 스위프트가 추측해주니깐.
다만, 이름이 같을 때는 스위프트도 헷갈릴 수 가 있으니깐, 제대로 알려주자.
Modifying Value Types from within Instance Methods
Stuctures와 enumerations는 value types임. 그래서, Instance methods내에서 properties를 변경할수가 없어.
but 방법이 있어.
Assigning to self Within a Mutationg Method
self를 사용한 설정
Type Methods
Type Methods는 특정 타입 자체에서 호출해 사용함. Instance Methods는 Instance내에서 사용했지만,이것을 사용하려면, func 앞에 static 이나 class 키워드를 추가해야해.class method를 사용하면 서브클래스에서 오버라이드 할 수 있어.