메서드에는 두 가지 종류가 있다.
- 인스턴스 메서드(Instance Method)
- 타입 메서드(Type Method)
class Person {
func like() {
print("like")
}
}
let person = Person()
person.like()
person 이라는 인스턴스를 먼저 생성.을 사용해 메서드에 접근func이란 키워드 앞에 static 혹은 class가 붙으면, 그 메서드는 타입 메서드이다.class Person {
static func eat() {
print("eat")
}
class func run() {
print("run")
}
}
eat, run 모두 타입 메서드// 타입.함수이름
Person.run()
Person.eat()