self vs. Self in Swift - Everything You Need to Know!

Поделиться
HTML-код
  • Опубликовано: 2 фев 2025

Комментарии • 15

  • @rasheshbosamiya1482
    @rasheshbosamiya1482 6 часов назад

    nice explanation, thank you for sharing.

  • @AndrewDChristie
    @AndrewDChristie 22 часа назад

    Thanks!

  • @helloworld4303
    @helloworld4303 6 дней назад

    Thanks Stewart. Definitely one of the more overlooked topics.

    • @StewartLynch
      @StewartLynch  5 дней назад

      I agree. It gets missed by a lot of people.

  • @AlanRick26
    @AlanRick26 12 дней назад

    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.

  • @Spacer-l3j
    @Spacer-l3j 23 часа назад +1

    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
      @StewartLynch  23 часа назад

      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

    • @crdave1988
      @crdave1988 22 часа назад

      Are you talking about compile time or run time performance?

    • @StewartLynch
      @StewartLynch  21 час назад

      Either. I just don’t think it would make much of a difference at all.

    • @crdave1988
      @crdave1988 21 час назад

      @@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.

    • @StewartLynch
      @StewartLynch  21 час назад +1

      Thanks for your input. Makes sense.

  • @GloverCom
    @GloverCom 11 дней назад

    "Although sometimes I wonder..." Hahah! :

  • @danielcrompton7818
    @danielcrompton7818 17 часов назад

    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