Guest User

Untitled

a guest
Mar 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. // Apple 문서 Protocol의 Property Requirements를 보고 있던 아래 문장에서 질문이 생겼습니다.
  2.  
  3. // Always prefix type property requirements with the static keyword when you define them in a protocol.
  4. // This rule pertains even though type property requirements can be prefixed with the class or static keyword
  5. // when implemented by a class:
  6. // 타입프로퍼티가 클래스에서 구현 될 때도 static 이나 class keyword가 붙어야 한다고 하는데
  7. // 아래 처럼 protocol에 static을 선언하고 class에서 static으로 구현하는 것 이해가 되는데
  8. // protocol 에 static 사용
  9. protocol AnotherProtocol {
  10. static var someTypeProperty: Int { get set }
  11. }
  12.  
  13. class clsssConform:AnotherProtocol{
  14. static var someTypeProperty: Int = 10
  15. // 타입프로퍼티는 초기화를 하거나 get set을 써야함
  16. }
  17.  
  18. // class로 구현하는 건 어떤 경우인지 모르겠습니다
  19. // 궁금해서 protocol에 class property를 선언하면
  20. // class properties are only allowed within classes 이렇게 에러가 뜨고
  21. //
  22. protocol AnotherProtocol {
  23. class var someTypeProperty: Int { get set }
  24. }
  25.  
  26. // 아래처럼 protocol에 static으로 선언하고 c
  27. // class에서 class property로 구현해도
  28. // class properties are only allowed within classes 이렇게 에러가 뜹니다.
  29. protocol AnotherProtocol {
  30. static var someTypeProperty: Int { get set }
  31. }
  32.  
  33. class clsssConform:AnotherProtocol{
  34. class var someTypeProperty: Int = 10
  35. // 타입프로퍼티는 초기화를 하거나 get set을 써야함
  36. }
Add Comment
Please, Sign In to add comment