Thank you Pitt for this. It's really visual and helps me understand the concept of opaque types much better 🙏
@swiftandtips2 жыл бұрын
You’re welcome Joe! ☺️
@benhwang63783 жыл бұрын
It's really helpful ! Thanks for your video , Amazing !
@swiftandtips3 жыл бұрын
Thank you Ben!
@aleksandrzinovev429 Жыл бұрын
Thanks ) Really good explanation
@roman32492 жыл бұрын
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"
@swiftandtips2 жыл бұрын
Hi Roman, yes, that’s possible on Swift 5.7+ This video was recorded with Swift 5.4 🥲
@yali_shanda3 жыл бұрын
Very well presented, keep it up!
@swiftandtips3 жыл бұрын
Thanks for your support 😁🙌🏻
@kyleclark13153 жыл бұрын
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`
@swiftandtips3 жыл бұрын
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!
@adlsfreund3 жыл бұрын
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!
@swiftandtips3 жыл бұрын
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 🙌🏻
@adlsfreund3 жыл бұрын
@@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!
@swiftandtips3 жыл бұрын
Sure, actually Pretty soon I will talk about Combine and then introduce type erasing after seeing eraseToAnyPublisher(). Stay tuned 😉!