Want to go deeper with Swift and iOS Dev? Check out my iOS Dev courses - seanallen.teachable.com
@Ni7ram Жыл бұрын
hey sean! i really really appreciate the chill and slower talking.. i know everyone talks super fast on YT , but on programming videos and such giving time to think is muuch needed. great video! very well explained 👏
@seanallen Жыл бұрын
Thanks. I usually get comments about speaking too fast 😂
@omnikong Жыл бұрын
Finally, I understand Generics! Thanks, Sean.
@seanallen Жыл бұрын
Happy to hear it!
@vickywang5049 Жыл бұрын
Well explained the usage of generic type! However, when I watch this video, I was expecting to hear about the difference of function with generics (similar to "template" in C++) vs. function with protocol-typed parameters. Basically, Swift allows both to achieve polymorphism. The following code would have exactly same outcome with driveHome() and genericDriveHome(): protocol Drivable { func drive() } struct Motorcycle: Drivable { func drive() { print("I'm a motorcycle. I'm going home.") } } struct Car: Drivable { func drive() { print("I'm a car. I'm going home.") } } func driveHome(vehicle: Drivable) { vehicle.drive() } func genericDriveHome(vehicle: T) { vehicle.drive() } let m = Motorcycle() let c = Car() driveHome(m) genericDriveHome(m) driveHome( c) genericDriveHome( c) In fact, if I use the same func name: func driveHome(vehicle: T){ vehicle.drive() } and call driveHome(m), the protocol typed function is favored. . . . I found the answer on StackOverflow, if you have the same question as me: stackoverflow.com/questions/38446487/what-is-the-in-practice-difference-between-generic-and-protocol-typed-function-p/41490551#41490551
@danstoian7721 Жыл бұрын
1:50 So when to use generics as opposed to just "some Drivable"?
@saeedrahmatolahi462 Жыл бұрын
Sean allen you are the best, explain everything very nice and simple so everyone can understand it easily 😊👍
@seanallen Жыл бұрын
Thanks for the kind words, Saeed.
@ruslangaliev5050 Жыл бұрын
Thank you for the video! You explain complex things in simple terms!
@seanallen Жыл бұрын
Glad you enjoy them, Ruslan!
@carlosswiftdev2703 Жыл бұрын
Good video :) you can use the max(_:_:) function which takes two Comparable types. print(max(valueOne, valueTwo), "is the highest value")
@seanallen Жыл бұрын
I knew there was a better way.
@JasonMitchellAZ Жыл бұрын
Great explanation and examples
@seanallen Жыл бұрын
Thanks Jason!
@mipmap2565 ай бұрын
One thing I don't understand, since you provide protocol for Generic type, why not just use protocol directly.
@rparham1997 Жыл бұрын
Can you do a video on protocols?
@seanallen Жыл бұрын
It's on my very long video idea list. So many video ideas, so little time :)
@roh9934 Жыл бұрын
How do you choose the protocol? like Decodable, comparable?
@rkarnes6304 Жыл бұрын
Sean, what’s your recommendation for someone to learn Swift coming from a C++ background 25 years ago, then Java 17 years ago. I’ve done virtually no coding since 2006, but want to get back into it for Vision Pro. (Shoot me any questions you have if needing to lock down further background information before making a recommendation.) Thanks much! I really want to do some awesome Vision Pro apps.
@yt-11618 ай бұрын
Which theme are you using in xcode
@seanallen8 ай бұрын
It's called Midnight
@bosch5053 Жыл бұрын
Thank you for the video!
@seanallen Жыл бұрын
My pleasure!
@faruuqqayyum3811 Жыл бұрын
Can you do a video for "Opaque Types"?
@seanallen Жыл бұрын
I'll add it to the idea list. However that list is VERY long :)