Рет қаралды 6,385
In this video, we will explore the power of generics in Swift and how they can be used to create reusable and flexible code. We will start by understanding the basics of generics and how they work in Swift. We will also explore how generics can be used in various scenarios such as creating generic data structures and writing reusable functions and classes.
By the end of this video, you will have a solid understanding of how generics can be used to create reusable and flexible code in Swift, allowing you to write cleaner, more maintainable, and more efficient code.
BackgroundGradientView: gist.github.com/pitt500/e4876...
Content:
0:00 - Intro
0:35 - What are generics?
5:50 - Why not using Any instead of generics?
9:39 - Type Constraints
12:22 - Generic Types
15:52 - Extending a generic type
17:13 - Using generics in SwiftUI
22:52 - Outro
------
References:
- docs.swift.org/swift-book/Lan...
- developer.apple.com/videos/pl...
- www.swiftbysundell.com/basics...
Source 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