Static properties and methods - Swift for Complete Beginners

Поділитися
Вставка
  • Опубліковано 26 гру 2024

КОМЕНТАРІ • 14

  • @caioliv
    @caioliv Рік тому +2

    His didactic is just impeccable! I've never seen anyone explaining complex things so easy and full of examples like he does! Thank you so much for all of this content!! It's hard to believe it's free.

  • @twostraws
    @twostraws  3 роки тому +9

    I made a small mistake in the audio - sorry about that! At 0:17 I meant to say "other instances of the same struct" rather than "other structs of the same instance" 🤦‍♂️

  • @bgriffin5447
    @bgriffin5447 3 роки тому +9

    You are the Morgan freeman of code. So soothing and precise.
    This topic was great have been using static properties for dummy data but never really understood why. 👍🏼

  • @rajat_kumar
    @rajat_kumar Місяць тому

    Hi, I started with Swift recently and I know it is 3 years old video. I was following along with the School struct but got the error on the line "static var studentCount = 0".
    the error is "Static property 'studentCount' is not concurrency-safe because it is nonisolated global shared mutable state"
    Can you please explain this error and how can I handle this error?

  • @samsHandle
    @samsHandle 2 місяці тому

    Wouldn’t it be better to create AppData as an enum so that it cannot be accidentally instantiated?

  • @bayraminanc885
    @bayraminanc885 3 роки тому

    Great teacher

  • @chezchezchezchez
    @chezchezchezchez 3 місяці тому

    It works exactly the same way in c#

  • @saurabhbisht2181
    @saurabhbisht2181 2 роки тому

    Awesome

  • @anonymous_user21
    @anonymous_user21 Місяць тому

    Why is Taylor swift in all of the vids? But nice vids, good explanation. I’ve been searching for an actual tutor instead of being self taught(going to random vids)

    • @twostraws
      @twostraws  Місяць тому +1

      Why is Taylor Swift mentioned in videos about a programming language called Swift? 😅

  • @ahmetonursahin151
    @ahmetonursahin151 3 роки тому

    i love u paul

  • @jlkeegan
    @jlkeegan 2 роки тому +2

    Paul I'm loving your entire series, but I have to strongly disagree with your choice of an example here (the School one) for static. School barely fits as an example, but if you HAD to use it, you could have a static called totalStudentsEverywhere or something, and in the add method you could add increment the non-static studentCount and then also the totalStudentsEverywhere value as well. You could show us you creating three different schools, adding two people to the first school, adding 1 to the second school, and adding four to the third school, then call each school's printCount() method, and then call a static printTotalCountEverywhere() method. You'd have to warn people that this isn't a great example because what if you ended up having schools created by some copy or something, and there was no good way to reset the totalStudentsEverywhere value without some reset etc.. but it would get across the idea that those values are global - all School objects share that value. I worry for anyone looking at the example you have in that first half. Sorry that my first comment has to be a criticism.. Keep up the good work!

  • @dugrut1325
    @dugrut1325 2 роки тому +3

    not to be rude: the reason for use of 'static' may make perfect sense but your explanations does not... sorry.

    • @darklen14
      @darklen14 10 місяців тому

      perfectly explained to shared constant data throughout the app. No need to create a new instance of a static object. It is created once and used whenever and wherever.