Some stuff like “capture” that I didn’t know, and perhaps don’t need (future video?) but the content of this video is incredibly useful. It clarifies in slow motion some extremely important Swift concepts.
Just asking, Isn't it a good idea to specify the property type instead of using var name = " ", we could write var name: String = " "? For a small project, yeah, but I'm thinking about a massive project where if you don't specify the type, Swift has to infer it for every property that doesn’t have a specified type, essentially making it figure out what the type could be. My point is that if the type is specified and we make a habit of doing this, we could help improve Swift’s performance by reducing the work it needs to do, right?
@@StewartLynch Runtime there would be no difference. Compile time there can be but very minor. Compile time it has to check type in both cases. Even if we mention the type it has to check that the type provided by the developer is the right one so the overall difference is very minor. There were some specific cases where type infer was taking significant compile time but most of them should have been improved.
Awesome Stewart, I've struggled with this for a long time, your video really helped me understand it a whole lot more! struct MyStruct { } Here is what I picked up: - MyStruct().self refers to the current instance of a structure or class. This can be used inside or outside a structure or class. - MyStruct.Self (.Self on the actual structure/class) refers to the "type as a value" -- like the "value of the structure/class type - MyStructType is the type hint for the value of the type (MyStruct.Self). E.g. func do(thisOn t: T.Type) { } do(thisOn: String.self) The doThisOn: function ASKS FOR the type of a type with .Type. this is given with type.Self
nice explanation, thank you for sharing.
Thanks!
Thank you!
Thanks Stewart. Definitely one of the more overlooked topics.
I agree. It gets missed by a lot of people.
Some stuff like “capture” that I didn’t know, and perhaps don’t need (future video?) but the content of this video is incredibly useful. It clarifies in slow motion some extremely important Swift concepts.
Just asking, Isn't it a good idea to specify the property type instead of using var name = " ", we could write var name: String = " "? For a small project, yeah, but I'm thinking about a massive project where if you don't specify the type, Swift has to infer it for every property that doesn’t have a specified type, essentially making it figure out what the type could be. My point is that if the type is specified and we make a habit of doing this, we could help improve Swift’s performance by reducing the work it needs to do, right?
I have not heard anyone make that case before. I am not an expert here, but I would think that would make very little if any difference
Are you talking about compile time or run time performance?
Either. I just don’t think it would make much of a difference at all.
@@StewartLynch Runtime there would be no difference. Compile time there can be but very minor. Compile time it has to check type in both cases. Even if we mention the type it has to check that the type provided by the developer is the right one so the overall difference is very minor. There were some specific cases where type infer was taking significant compile time but most of them should have been improved.
Thanks for your input. Makes sense.
"Although sometimes I wonder..." Hahah! :
Awesome Stewart, I've struggled with this for a long time, your video really helped me understand it a whole lot more!
struct MyStruct { }
Here is what I picked up:
- MyStruct().self refers to the current instance of a structure or class. This can be used inside or outside a structure or class.
- MyStruct.Self (.Self on the actual structure/class) refers to the "type as a value" -- like the "value of the structure/class type
- MyStructType is the type hint for the value of the type (MyStruct.Self).
E.g.
func do(thisOn t: T.Type) { }
do(thisOn: String.self)
The doThisOn: function ASKS FOR the type of a type with .Type. this is given with type.Self