Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Apple 문서 Protocol의 Property Requirements를 보고 있던 아래 문장에서 질문이 생겼습니다.
- // Always prefix type property requirements with the static keyword when you define them in a protocol.
- // This rule pertains even though type property requirements can be prefixed with the class or static keyword
- // when implemented by a class:
- // 타입프로퍼티가 클래스에서 구현 될 때도 static 이나 class keyword가 붙어야 한다고 하는데
- // 아래 처럼 protocol에 static을 선언하고 class에서 static으로 구현하는 것 이해가 되는데
- // protocol 에 static 사용
- protocol AnotherProtocol {
- static var someTypeProperty: Int { get set }
- }
- class clsssConform:AnotherProtocol{
- static var someTypeProperty: Int = 10
- // 타입프로퍼티는 초기화를 하거나 get set을 써야함
- }
- // class로 구현하는 건 어떤 경우인지 모르겠습니다
- // 궁금해서 protocol에 class property를 선언하면
- // class properties are only allowed within classes 이렇게 에러가 뜨고
- //
- protocol AnotherProtocol {
- class var someTypeProperty: Int { get set }
- }
- // 아래처럼 protocol에 static으로 선언하고 c
- // class에서 class property로 구현해도
- // class properties are only allowed within classes 이렇게 에러가 뜹니다.
- protocol AnotherProtocol {
- static var someTypeProperty: Int { get set }
- }
- class clsssConform:AnotherProtocol{
- class var someTypeProperty: Int = 10
- // 타입프로퍼티는 초기화를 하거나 get set을 써야함
- }
Add Comment
Please, Sign In to add comment