Associated Type
-
Associated type?Swift 2022. 1. 4. 19:54
Associated Type은 뭘까? 사람마다 접하거나 사용한 부분이 다르지만, 나는 처음 여기서 봤다. 짜잔~ 바로 저기 있는 associatedtype 이다. AssociatedType ? 실제로 associatedtype 은 Generics 아래 위치해 있다. https://docs.swift.org/swift-book/LanguageGuide/Generics.html generic의 성질이 있다는 말인데, 바로 위에서 처럼 protocol에서 사용된다. 설명된 예제를 보면 저런식으로 protocol에 Item 이라는 associatedtype을 선언해서 사용할 수 있는데 사용할때 아래처럼 Int 로 선언해서 사용할 수도, Element로 선언해 사용할 수도 있는 셈이다. 결론 결론 이랄것도 없지만..