Opaque types: Masking your concrete types

  Рет қаралды 4,833

Swift and Tips

Swift and Tips

Күн бұрын

Пікірлер: 20
@cil7ea
@cil7ea 2 жыл бұрын
one of the best explanations out there
@swiftandtips
@swiftandtips 2 жыл бұрын
Thank you very much! ❤️
@rungxanh2901
@rungxanh2901 2 жыл бұрын
Thank you Pitt for this. It's really visual and helps me understand the concept of opaque types much better 🙏
@swiftandtips
@swiftandtips 2 жыл бұрын
You’re welcome Joe! ☺️
@benhwang6378
@benhwang6378 3 жыл бұрын
It's really helpful ! Thanks for your video , Amazing !
@swiftandtips
@swiftandtips 3 жыл бұрын
Thank you Ben!
@aleksandrzinovev429
@aleksandrzinovev429 Жыл бұрын
Thanks ) Really good explanation
@roman3249
@roman3249 2 жыл бұрын
Hi. In the second example we actually have a sequence of integers. So can we somehow indicate that? Something like: "--> some Sequence" or "--> some Sequence where Element = Int"
@swiftandtips
@swiftandtips 2 жыл бұрын
Hi Roman, yes, that’s possible on Swift 5.7+ This video was recorded with Swift 5.4 🥲
@yali_shanda
@yali_shanda 3 жыл бұрын
Very well presented, keep it up!
@swiftandtips
@swiftandtips 3 жыл бұрын
Thanks for your support 😁🙌🏻
@kyleclark1315
@kyleclark1315 3 жыл бұрын
Awesome summation. Thank you for sharing your knowledge! regarding the use of Equatable at 20:09.. Is there a workaround or extension you can put on Animal, so that the protocol `Animal: Equatable` wont give an error for the signature `adoptPet() -> Animal`
@swiftandtips
@swiftandtips 3 жыл бұрын
Hi Kyle, good question, unfortunately not. If you have to use Equatable for your protocol, then opaque types are the only way to do it, however you would lose flexibility of sending multiple types that conform same protocol. It’s a tradeoff, will depend on your needs. Thank you for the support!
@adlsfreund
@adlsfreund 3 жыл бұрын
Nice video! I didn't realize that opaque types is so important to SwiftUI, but it makes sense. I'm a bit confused about the very last part. Do you mean that protocols cannot *require* users to mark properties as for example `var body: some View` instead of allowing `var body: Text` ? Or were you referring to just the syntax in the protocol definition? Congratulations on the channel!
@swiftandtips
@swiftandtips 3 жыл бұрын
Hi @adlsfreund, I meant the syntax. You cannot declare opaque types in protocols, which means you can return a concrete type for a property or method in a protocol’s implementation or use an opaque type because “some” is not part of the protocol, It’s optional for the user. And as I mentioned, the concrete type and the opaque type are “the same” internally for Swift 😉. Let me know if it makes more sense now. Also, check the swift proposal in the description. Thank you for your support 🙌🏻
@adlsfreund
@adlsfreund 3 жыл бұрын
​@@swiftandtips Thanks for your answer! I understand you now. Opaque types seems simple to me, but not sure about designing protocols with them in mind. I need more experience with protocols beyond just using SwiftUI. I'd like to see a video about type-erasing wrappers like AnyView. Why are they needed, and how to make my own? Thanks!
@swiftandtips
@swiftandtips 3 жыл бұрын
Sure, actually Pretty soon I will talk about Combine and then introduce type erasing after seeing eraseToAnyPublisher(). Stay tuned 😉!
@adlsfreund
@adlsfreund 3 жыл бұрын
@@swiftandtips Excellent!
@marduck19
@marduck19 3 жыл бұрын
9:18 I am so lazy to read this 😂😂
"any" Keyword and Existential types in Swift
4:59
Swift and Tips
Рет қаралды 10 М.
Generics in Swift: Protocols with associated types
15:37
Swift and Tips
Рет қаралды 10 М.
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Rust: Generics, Traits, Lifetimes
35:34
The Dev Method
Рет қаралды 51 М.
Protocols With Associated Types vs Generics (Swift 5)
12:21
SwiftBook
Рет қаралды 7 М.
How do Actors work in Swift?
19:05
Swift and Tips
Рет қаралды 4,4 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 188 М.
Swift Generics: The Key to Reusable and Flexible Code
23:47
Swift and Tips
Рет қаралды 7 М.
Golang: The Last Interface Explanation You'll Ever Need
17:58
Flo Woelki
Рет қаралды 28 М.
Type Erasure In Swift | iOS Development
15:19
iOS Academy
Рет қаралды 8 М.
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 87 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 725 М.
Halloween is coming
0:12
Younes Zarou
Рет қаралды 3,4 МЛН
пранк: псих сбежал из дурдома
0:53
Анна Зинкина
Рет қаралды 1,7 МЛН
The Million view clip on China's Tiktok P2428 #shorts #gochannel
0:15
Go Channel TV
Рет қаралды 29 МЛН
Американцы красят асфальт?
0:27
BAZAR CLUB
Рет қаралды 188 М.
Что такое дагестанский кирпичный завод!
0:53
АВТОБРОДЯГИ - ПУТЕШЕСТВИЯ НА МАШИНЕ
Рет қаралды 746 М.