Generics in Swift: Where Clauses (and something else!)

  Рет қаралды 2,594

Swift and Tips

Swift and Tips

Күн бұрын

Hello guys, welcome to another video! Today we will continue with the Generics series talking about where clauses to constraint our associated type to a specific domain and modularize our code with the powers of generics and Swift's type inference. Also, in the end, I have a challenge for you: Merge two stacks and generate a new one, let's see if you got the idea about where clauses 👌🏼. Let me know in the comments if your solution was different from mine 😉!
Before continue I recommend you to watch the previous episodes:
Part 1 (Generics) : • Swift Generics: The Ke...
Part 2 (Associated types): • Generics in Swift: Pro...
Started code for this video: gist.github.com/pitt500/c759b...
Content:
0:00 - Intro
0:35 - What are where clauses?
5:25 - Contextual Where Clauses
11:45 - Challenge: Merge two stacks
19:11 - Outro
------
References:
- docs.swift.org/swift-book/Lan...
- developer.apple.com/videos/pl...
- www.swiftbysundell.com/basics...
Final code showed in this video: github.com/pitt500/swift-and-...
------
Other videos in the channel:
- Protocols in Swift: • Protocols
- UIKit in SwiftUI: • UIKit in SwiftUI
- Struct vs Classes: • Structs vs classes in ...
-----
Don't forget to subscribe to the channel, like it, and follow me on social media:
Twitter:
/ swiftandtips
/ pitt500
Finally, ask me for a video you would like to see next 😄!
Credits:
- Music by Wataboi from pixabay.com/
- Video edited with LumaFusion

Пікірлер: 20
@praveen5186
@praveen5186 2 жыл бұрын
Really awesome...great work👍
@swiftandtips
@swiftandtips 2 жыл бұрын
Thank you Praveen! 🙌🏻
@sukhmanikaur9755
@sukhmanikaur9755 2 жыл бұрын
Really helpful.......great work👏
@swiftandtips
@swiftandtips 2 жыл бұрын
Thank you @Sukhmani 😃
@ssaai
@ssaai 2 жыл бұрын
This channel name and content is awesome. 🥰👏👏👏👏👏👏
@swiftandtips
@swiftandtips 2 жыл бұрын
Thank you Sai 😄!
@rakesh58652
@rakesh58652 3 жыл бұрын
Super
@adlsfreund
@adlsfreund 3 жыл бұрын
Yes, I solved the challenge, but without opaque return type. 😄 Also, last time I was wondering why to use Stack protocol when the generic MyStack can work the same without a protocol, but this video shows you cannot write a merge function like this without the protocol. At least I tried and got compiler errors. Where-clauses really had me confused at first, just like associated types, and I'm feeling more comfortable with them now. Kudos to you, these tutorials are excellent!
@swiftandtips
@swiftandtips 3 жыл бұрын
Thank you so much @adlsfreund!
@hoshmovie
@hoshmovie Жыл бұрын
regarding the challenge, I think we can only iterate over the stack to avoid calling pop that way we don't have to pass a value type as reference which I thin think in most of the cases is not a good idea
@swiftandtips
@swiftandtips Жыл бұрын
Hi Marco, Sure, this is just an example to test where clauses. Of course there are better ways to solve this in real life. Anyway, thanks for the comments!😃
@andrejkling3886
@andrejkling3886 2 жыл бұрын
Advanced lessons... thank you
@waheedafolabi6929
@waheedafolabi6929 Жыл бұрын
You didn’t produce the next videos in this series right? Perhaps I missed it… Great concepts. Thanks 🎉
@swiftandtips
@swiftandtips Жыл бұрын
Hi Waheed, this is the playlist with the whole series kzfaq.info/sun/PLHWvYoDHvsOVP-9UvMBBYJCqxrJ3E8Cry Would you recommend another topic to add? Thanks 😊
@waheedafolabi6929
@waheedafolabi6929 Жыл бұрын
@@swiftandtips oh! I have seen the series actually. I thought there were more to be expected as you mentioned in the last video in this series.
@hickam16
@hickam16 Жыл бұрын
@@waheedafolabi6929 I think this is the next video: kzfaq.info/get/bejne/eZqHhKmGnLfWnYE.html
@mohdkashif289
@mohdkashif289 Жыл бұрын
awesome content no doubt! Regarding the return type, what other option we have apart from opaque types? While making sure it is abstract. Again, thanks for the quality content ❤ @swiftandtips
@swiftandtips
@swiftandtips Жыл бұрын
Thanks for your comment! Take a look to this one about existential types: "any" Keyword and Existential types in Swift kzfaq.info/get/bejne/jcdoq7eErb7DgIE.html
Generics in Swift: Protocols with associated types
15:37
Swift and Tips
Рет қаралды 9 М.
Opaque types: Masking your concrete types
22:18
Swift and Tips
Рет қаралды 4,3 М.
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 109 МЛН
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 66 МЛН
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 29 МЛН
C# Generics - The complete guide
18:43
Tarodev
Рет қаралды 39 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 169 М.
Advanced Golang: Generics Explained
13:37
Code With Ryan
Рет қаралды 59 М.
How to use generics in TypeScript
11:46
Andrew Burgess
Рет қаралды 36 М.
Generic Associated Types: A Practical Introduction
8:53
chris biscardi
Рет қаралды 12 М.
Intro to Sendable in Swift 5 (2022)
11:23
iOS Academy
Рет қаралды 12 М.
Why The Windows Phone Failed
24:08
Apple Explained
Рет қаралды 235 М.
How to use a Switch Statement in Swift | Beginner
11:27
Sean Allen
Рет қаралды 8 М.
Swift - Generics (Advanced)
27:51
iOS Solves
Рет қаралды 399
Bluetooth connected successfully 💯💯
0:16
Blue ice Comedy
Рет қаралды 1,6 МЛН
Tag him😳💕 #miniphone #iphone #samsung #smartphone #fy
0:11
Pockify™
Рет қаралды 4,4 МЛН
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 18 МЛН
Мой новый мега монитор!🤯
1:00
Корнеич
Рет қаралды 658 М.
Сколько реально стоит ПК Величайшего?
0:37