iOS/Swift some, any - some - opaque type 특정 프로토콜을 준수하는 것을 나타내는 불투명 유형을 만들기 위해 프로토콜과 함께 사용된다. 불투명 유형의 기본 유형은 변수 scope 내에서 하나로 고정되어야 합니다. 같은 구체 타입의 새로운 인스턴스를 변수에 할당하는 것도 금지되어 있습니다. 배열이나 리턴타입에서도 하나의 구체 타입으로 고정되어야 합니다. any - existential type Existential Type (Existentials, 실존타입, 실존유형)protocol과 associated type을 이용하여 특정 바운더리로 제약시키는 방법 Swift 5.7부터 실존 타입에는 any를 쓰는 것이 필수다. 왜냐하면 실존타입을 사용하는 것이 동적 타입 결정으로 인한 성능 저하를 불러올 수 있음에도 너무 쉽게 사용할 수 있었기 때문이다. 위의 예제에서 some을 모두 any로 바꾸면 모든 에러가 해결된다. 이를 이용해 dynamic dispatch를 구현할 수 있다. 그러나 실존 타입끼리 == 연산자는 사용할 수 없다(불투명 타입끼리는 가능). 각 실존타입의 기본 구체 유형이 항상 같다고 보장할 수 없기 때문이다. 실존 타입은 불투명 타입에 비해 덜 효율적이다. 가능하다면 제네릭으로 대체하는 것이 좋다. 출처 https://swiftsenpai.com/swift/understanding-some-and-any/ Understanding the "some" and "any" keywords in Swift 5.7 - Swift Senpai Feeling confused about how to use the "any" and "some" keywords, and what are their differences? This article will clear things up for you. swiftsenpai.com https://swiftsenpai.com/swift/dynamic-dispatch-with-generic-protocols/ How to Achieve Dynamic Dispatch Using Generic Protocols in Swift 5.7 - Swift Senpai With improvements in Swift 5.7, achieving dynamic dispatch on a protocol with associated types has never been easier. Here's how. swiftsenpai.com https://www.donnywals.com/what-is-the-any-keyword-in-swift/ What is the “any” keyword in Swift? – Donny Wals Learn everything you need to know about the any keyword that was added in Swift 5.6 and Xcode 13.3 www.donnywals.com https://www.donnywals.com/generics-in-swift-explained/ Generics in Swift explained – Donny Wals Learn what generics are in Swift using Array as an example. In this article I also show you how you can begin using simple generics in your apps straight away. www.donnywals.com 반응형 공유하기 게시글 관리 스위프트 깎는 개발자 저작자표시 비영리 동일조건 'iOS > Swift' 카테고리의 다른 글 캡쳐리스트 (0) 2023.11.17 [Tip] RxSwift 콜스택만 잔뜩있는 크래시 로그로 디버깅하기 (0) 2023.11.16 protocol을 채택하지 않는 struct도 3word가 넘으면 데이터가 heap에 저장될까? (1) 2023.07.19 LetSwift in 판교 2차 후기 (0) 2020.01.16 iOS에서의 이미지 리사이징에 대하여 (1) 2019.09.27 Contents 당신이 좋아할만한 콘텐츠 캡쳐리스트 2023.11.17 [Tip] RxSwift 콜스택만 잔뜩있는 크래시 로그로 디버깅하기 2023.11.16 protocol을 채택하지 않는 struct도 3word가 넘으면 데이터가 heap에 저장될까? 2023.07.19 LetSwift in 판교 2차 후기 2020.01.16 댓글 0 + 이전 댓글 더보기