Generics in Swift: Protocols with associated types
Hello guys, welcome to another video! Today we will continue with the Generics series talking about protocols with associated types. SwiftUI views were made with these special protocols, How can we create our own associated types? Can I create a generic protocol with square brackets? How does Swift infer associated types?... we will solve all those questions and also see how to use protocols when we found the error "Protocol can only be used as a generic constraint...". Before continue I recommend you to watch the first episode: Part 1: https://youtu.be/W947iXBIFu4 Content: 0:00 - Intro 0:29 - Associated types in SwiftUI 0:52 - What are associated types? 6:43 - Generic type with a protocol with associated type 9:52 - Extending from a protocol with associated type 12:28 - How to solve "Protocol can only be used as a generic constraint ..."? 14:50 - Outro ------ References: - https://docs.swift.org/swift-book/LanguageGuide/Generics.html - https://developer.apple.com/videos/play/wwdc2018/406 - https://www.swiftbysundell.com/basics/generics/ Source code showed in this video: https://github.com/pitt500/swift-and-tips/blob/main/Generics/AssociatedTypes/AssociatedTypes.playground/Contents.swift ------ Other videos in the channel: - Protocols in Swift: https://youtube.com/playlist?list=PLHWvYoDHvsOX_H712wbhzSW0xqHsFy2j9 - UIKit in SwiftUI: https://youtube.com/playlist?list=PLHWvYoDHvsOX8vB95YIkv_r5e5IXWcyu2 - Struct vs Classes: https://youtu.be/zOeC7pxOIhk ----- Don't forget to subscribe to the channel, like it, and follow me on social media: Twitter: https://twitter.com/swiftandtips https://twitter.com/pitt500 Finally, ask me for a video you would like to see next 😄! Credits: - Music by Wataboi from https://pixabay.com/ - Video edited with LumaFusion
Download
0 formatsNo download links available.