Swift Classes and Structures Explained

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

КОМЕНТАРІ • 270

  • @seanallen
    @seanallen  4 роки тому +1

    Watch Next - iOS Take Home Project - Job Interview Practice - Free Preview - ua-cam.com/video/MSIe2y6Fee8/v-deo.html

  • @sulabhagarwal3697
    @sulabhagarwal3697 7 років тому +132

    I just wonder how did it came to your mind such a simple yet best analogy to explain the concept. Its really impressive.Genious

    • @seanallen
      @seanallen  7 років тому +17

      Thanks! I've always been good at coming up with analogies to explain things in a relatable way. Thanks for watching!

    • @Belizianboi13
      @Belizianboi13 7 років тому +2

      Yea good job bro!

    • @bigmtnstudio
      @bigmtnstudio 7 років тому +3

      I agree, Sean, I've been watching your videos and you do an awesome job with the analogies! You're a natural teacher! 😃

    • @tenminutetokyo2643
      @tenminutetokyo2643 7 років тому +1

      Sulabh Agarwal it’s called common sense ‘genius’

  • @michaelamiro6076
    @michaelamiro6076 5 років тому +12

    Impressive 2 years later. Point driven home. Not just to the door. To the very heart of home.

    • @seanallen
      @seanallen  5 років тому

      Glad it was helpful 😀

  • @tonylinfreedom
    @tonylinfreedom 6 років тому +3

    Easy to understand video. I initially searched for Google with key words "Swift class vs struct" in video category and watched the first video done by others in the search results. Your video is better than the first video returned by Google.

    • @seanallen
      @seanallen  6 років тому +1

      Thanks Tony! Glad you found it helpful.

  • @isaacclark9825
    @isaacclark9825 7 років тому +1

    Your videos on interview questions are what I like best. More please!

    • @seanallen
      @seanallen  7 років тому

      Thanks Isaac! I'm almost done with this series. I still have debugging, closures, and networking to cover... But after that, I'm open to suggestions if you've come across any!

  • @harshtokas123
    @harshtokas123 3 роки тому +1

    Best example out there. I have started learning swift coding 3 days back and it made me wonder what is the difference between these two? SO glad I stumbled across this video.

  • @royce623
    @royce623 3 роки тому +1

    Why struct can't inheritance, could you please explain in brief?

  • @yashkhandha
    @yashkhandha 5 років тому +1

    Google doc and emailing word doc analogy to references and values ! BANG ON !!!!!

    • @seanallen
      @seanallen  5 років тому +1

      Glad you enjoyed that analogy, Yash!

    • @crusherw6873
      @crusherw6873 5 років тому

      really made sense. excellent work!!! love it

  • @nicholasdimaria
    @nicholasdimaria 4 роки тому +3

    I was very confused about this subject until I found your video. Thank you for the great analogy and excellent lesson!

    • @seanallen
      @seanallen  4 роки тому +1

      Glad it was helpful!

  • @joshuajean4683
    @joshuajean4683 2 роки тому +1

    Best analogy for the two, I got tripped on it in a book I bought and other videos. Thanks

  • @FaraazKhanTV
    @FaraazKhanTV 5 років тому +13

    Awesome analogy, understood it from the beginning

  • @synagridas13
    @synagridas13 7 років тому +5

    Your teaching skills are godlike - can’t believe i only just came across your channel. Awesome stuff man, keep it up

    • @seanallen
      @seanallen  7 років тому +1

      Thanks! Glad you're enjoying the channel.

    • @synagridas13
      @synagridas13 7 років тому

      Sean Allen let me throw out some tutorial ideas for you which I feel have not been covered properly in youtube: what do the app delegate and plist files do in detail, what is the app window set in app delegate and how to use multiple windows (to show global pop ups, for example), how does xcode combine and translate our storyboard file to our code, how to use awakeFromNib and Xib/Nib files. Thanks!

  • @seanallen
    @seanallen  7 років тому +5

    Struggling with the difference between classes and structs? Leave a question here, I'm happy to help.

    • @sathamhussain9299
      @sathamhussain9299 7 років тому +2

      Hey Sean, the way you explained is awesome. Just tell me when to use class and when to use struct. Thank you so much.

    • @seanallen
      @seanallen  7 років тому

      Thanks Satham! Glad you enjoyed and got value from the video.

    • @HodaPanther
      @HodaPanther 6 років тому +1

      Thanks for this (and all the other videos in this series). They are very helpful.
      Q: how about methods? Is there a difference in their ability to handle methods? Thanks.

  • @thinkinting
    @thinkinting 4 роки тому

    the excel vs google sheets analogy is excellent!!! it makes me understand the topic instantly, unlike some other tutorials.

  • @thomasnn
    @thomasnn 7 років тому +12

    Simple and to the point. Exactly what I needed

    • @seanallen
      @seanallen  7 років тому +1

      Glad you enjoyed it, Thomas!

  • @noblify299
    @noblify299 6 років тому +1

    your the best teacher i ever had in ios teaching... hats off
    keep going
    Your the best

  • @Mongerops
    @Mongerops 6 років тому +1

    dear lord, this was the best explanation I have found even better than what my instructor could come up with!

  • @sravk245
    @sravk245 4 роки тому

    No one could have explained this concept better. To the point, great video!

    • @seanallen
      @seanallen  4 роки тому

      Thanks for the kind words 😀

  • @anshuparihar3654
    @anshuparihar3654 7 років тому +1

    Although already said but once again i will say, your analogy is perfect here. It just got settled in my mind.

    • @seanallen
      @seanallen  7 років тому

      Glad you're enjoying the videos!

  • @GurjinderSingh-tf2dl
    @GurjinderSingh-tf2dl 6 років тому

    Thanks!. Can you explain when to use class and when to use struct?

  • @ezadens
    @ezadens 7 років тому +1

    Clear to the point, finally i can fully understand the difference. thank you very much, you're doing great job and inspiring us. keep up the good job.

    • @seanallen
      @seanallen  7 років тому

      Thanks Ezuu! Glad you finally understand the difference!

  • @sebbe4171
    @sebbe4171 5 років тому +2

    These videos are worth gold for me u explain so good

    • @seanallen
      @seanallen  5 років тому

      Thanks for the kind words, Sebbe. Happy to hear you find it helpful 😀

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

    simple yet great explanation!

  • @TheDesiWanderer
    @TheDesiWanderer Рік тому

    Thanks for the simplest and amazing explanation. I have 1 doubt, why are you using 'Let' for stolenMacBook but 'Var' for stoleniPhone ?

  • @GuitarreroDaniel
    @GuitarreroDaniel 4 роки тому +1

    I've just recently stumbled upon your channel and is terrific! Thank you very much, now you're my way to go when I want to learn a Swift Concept.

    • @seanallen
      @seanallen  4 роки тому +1

      Happy to hear that, Daniel. I've been taking a little break from new videos, but will be back in early September. See ya then!

  • @acja87
    @acja87 6 років тому

    Really great explanation. Thanks. For the struct example you set stoleniPhone to a variable instead of a constant which was the case for the stolenMacBook. Was that on purpose?

  • @vishwasmukund
    @vishwasmukund 6 років тому +1

    Thanks man. Your content is effective. Much better than most paid coursera courses. Keep up the good work

  • @nileshjdarji
    @nileshjdarji 5 років тому +1

    Awesome. One of the best explanations between classes and structs that I have came across. Thanks Sean.

    • @seanallen
      @seanallen  5 років тому

      Happy to hear it helped, Nilesh!

  • @asmatarunnum3071
    @asmatarunnum3071 7 років тому +1

    Best video on classes and structs i came across.....

    • @asmatarunnum3071
      @asmatarunnum3071 7 років тому +1

      Efficietly clears the actual concept

    • @seanallen
      @seanallen  7 років тому

      Thanks Asma! Glad you enjoyed it.

  • @mryup6100
    @mryup6100 6 років тому +7

    I loved the analogy!! I’m still a beginner and in the class I understand everything but the self.year and self.color. Is that necessary? Also what does it mean?

    • @seanallen
      @seanallen  6 років тому +3

      I'm assuming you're talking about the init method. If that's the case, when you initialize an instance of the class (create it), you need to set those properties. So we are setting the properties on that class to the information we pass via the parameters.

  • @bathong188
    @bathong188 3 роки тому +1

    This is an amazing explanation. Thank you!

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

    Very nicely explained. I'm thinking about learning Swift. I'll be checking out your content more in the future, hopefully. Cheers!

  • @codechamp2599
    @codechamp2599 6 років тому +2

    this logic is fuc*** cool , magnificent i would never forget it from now

    • @seanallen
      @seanallen  6 років тому +1

      haha, thanks. Happy to hear it was helpful 👍

  • @sergiobost4891
    @sergiobost4891 4 роки тому

    That was so easy to understand. Thanks
    Maybe you could explain the self. in another video

    • @seanallen
      @seanallen  4 роки тому

      Glad it was helpful! I've added the self keyword to my video to-d list.

  • @Mucksauce
    @Mucksauce 5 років тому

    I get it, but starting at 2:04 you create two constants and call them variables
    Then for the struct example at 3:59 you create a constant and a variable
    Does this effect the class or struct behavior?

  • @neerajjerauld
    @neerajjerauld 6 років тому +1

    Thanks for the brilliant example.. can you do one for Closure? mainly about why to use them and where to use them. *Trailing + autoclosures too .

    • @seanallen
      @seanallen  6 років тому

      I plan on redoing this series sometime in 2019 (as you can see these are starting to get old). At that time, I'll include closures.

  • @emin_ui
    @emin_ui 7 років тому +1

    Really well structured tutorials with fast explanations and info...tnx for this man, really helps a lot !

    • @seanallen
      @seanallen  7 років тому

      Glad you enjoyed it, EmiN!

  • @jasper5016
    @jasper5016 7 років тому +1

    Very different analogy. Wonderful and useful video.

    • @seanallen
      @seanallen  7 років тому

      Glad you enjoyed it, A P. Glad to hear it helped.

  • @cineverseproductions
    @cineverseproductions 4 роки тому

    I think almost every video of yours have my comment of thanks. And again, thanks sean for the simple and best analogy. 😄👍

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

    You earned yourself a damn subscription for this video. Thank you for the great content!

  • @Dennisvm82
    @Dennisvm82 7 років тому +2

    Perfect! Very well explained, Sean. Really loving the short video tutorials :-) keep it up!

    • @seanallen
      @seanallen  7 років тому

      +Dennis van Mazijk glad you enjoy it Dennis!

  • @kslazinski
    @kslazinski 4 роки тому +2

    Great video! Thanks for this. I understand and remember now :)

  • @jimneumann6099
    @jimneumann6099 6 років тому

    Why did you use var for the struct and let for the class?

  • @jonessmith8670
    @jonessmith8670 6 років тому +4

    Thank you very much! This is so clear!

  • @ivanpena7323
    @ivanpena7323 7 років тому +1

    Great work Sean! Enjoying your videos. Love the way you explain things. Thanks

    • @seanallen
      @seanallen  7 років тому

      +Ivan Pena thanks Ivan! Glad you're enjoying them. More on the way!

  • @wizzl8513
    @wizzl8513 5 років тому +1

    Your channel is a goldmine, keep up the great work !

    • @seanallen
      @seanallen  5 років тому

      Thanks for the kind words!

  • @martinmuldoon8166
    @martinmuldoon8166 6 років тому +1

    Thanks very much. Very clear now on use cases for Structs.

    • @seanallen
      @seanallen  6 років тому

      Glad you found it useful, Martin!

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

    When u started swift, how long did it take u to become good?

  • @RippleClips
    @RippleClips 4 роки тому

    Another point worth mentioning is that structs are read-only by default. Lost points in an interview because I didn’t know that

  • @TheMicheilsGrey
    @TheMicheilsGrey 6 років тому

    Isn't value types live in stack and reference in heap ? value types working more faster then reference types ?

  • @blinker-27
    @blinker-27 4 роки тому

    When we should use class and strut?

  • @lucasmoraes1971
    @lucasmoraes1971 7 років тому

    Great channel Sean, congratulations for your work. I wish the best for you !!

    • @seanallen
      @seanallen  7 років тому

      Thanks Lucas, I'm happy you're enjoying the videos. Hopefully they are helping!

  • @ebubeawachie
    @ebubeawachie 3 роки тому +1

    Amazing explanation. Finally I get it.

  • @yndrywjynsyn
    @yndrywjynsyn 6 років тому

    As usual, great video! I want to build an app that displays health tips based on the day, time of day, and the user's preferences (e.g. gender, age, diet). I'll use a Firebase Database. Each user will see personalized tips based on their preferences. I'm confused on how to build the data structures? Thanks in advance for your help!

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

    What is the difference between mutating and overriding a function

  • @Impulse_Photography
    @Impulse_Photography 5 років тому

    I always thought if I had a struct, and create an object, myobj. If I were to pass it like myfunct(mystruct& myobj) it would be passed by reference. Wouldn't it?

  • @DoubleCheapBurger
    @DoubleCheapBurger 4 роки тому

    Thanks a lot, dude! This is such an excellent example.

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

    Thanks for the explanation !
    nice Analogy !

  • @kiransonne7689
    @kiransonne7689 5 років тому

    can we create instance optional object in a class like var name:String?

  • @samr.4692
    @samr.4692 5 років тому

    Great analogy, nice clarification! Thank you...

  • @markme7092
    @markme7092 5 років тому +1

    I like this guy. He has wide & great knowledge. Thanks for good vid !

  • @valentinskukjans5911
    @valentinskukjans5911 7 років тому +1

    Great videos. Keep going!! what monitor a u using? (The big one near your laptop ) Thank You!

    • @seanallen
      @seanallen  7 років тому

      Thanks Valentins, it's an LG 34 inch curved Ultra-Wide. I did a video about my setup here that you might enjoy: ua-cam.com/video/ZiYx_4eeOms/v-deo.html

    • @valentinskukjans5911
      @valentinskukjans5911 7 років тому +1

      Thanks man.

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

    Great explanation. Does this not work in C++?
    #include
    using namespace std;
    class car
    {
    public:
    int wheels;
    string colour;
    car(int x,string y)
    {
    wheels=x;
    colour=y;
    }
    };
    int main()
    {
    car c1(10,"Blue");
    car c2=c1;
    c2.wheels=4;
    cout

  • @lukasm4821
    @lukasm4821 6 років тому +1

    Hi Sean! Thanks for making this explanation. I am just on my way to learning Swift programming and this helped me a lot. But there is still very much to learn for me. It seems a long journey.

    • @seanallen
      @seanallen  6 років тому

      Glad it was helpful, Lukas. You are right... it is a LONG journey, so patience is key. Most devs take at least 6-12 months of learning before finding their first job.

    • @lukasm4821
      @lukasm4821 6 років тому +1

      Patience and continous practice. Sometimes it is overwhelming for me, still forgeting a lot of new stuff I've learnd. Sometimes I feel so dumb in this area. In Poland, Swift is a niche so I think finding a job here will be difficult, but for some reasons I see the future in this programming language. Anyway, You've got a new subscriber.

    • @seanallen
      @seanallen  6 років тому

      Thanks Lukas... check out some of my videos about "how I became an iOS Dev in 7 months"... and other videos in my "Thoughts & Experiences" playlist. You'll find a lot of videos talking about that type of stuff.

  • @M8VXR
    @M8VXR 2 роки тому +1

    Great description

  • @rahafalhelo6974
    @rahafalhelo6974 7 років тому +2

    This is the best tutorial, thanks😍

    • @seanallen
      @seanallen  7 років тому

      Thanks Rahaf! Happy to hear it helped.

  • @SevenDeMagnus
    @SevenDeMagnus 6 років тому

    Hi what about enum? Is that a reference type or a value type? Does it take advantage of inheritance? Thank you.

  • @jumancamacho
    @jumancamacho 7 років тому +1

    Thanks for the magnific explanation!

    • @seanallen
      @seanallen  7 років тому

      No problem, Juan! Glad you enjoyed it!

  • @antonstafeyev3606
    @antonstafeyev3606 4 роки тому

    randomly played this video, I am coming from c++ and use out of curiosity, how do you copy a class in swift ?

  • @jelly1928
    @jelly1928 7 років тому

    love this channel, you helped me out so much

    • @seanallen
      @seanallen  7 років тому

      Glad it's helping, Hamann. Feel free to reach out with any questions.

    • @jelly1928
      @jelly1928 7 років тому

      Can you explain in detail what a protocol and a delegate are? I liked the example you used in this video about the excel sheet vs. the google doc, it cleared a lot up

    • @seanallen
      @seanallen  7 років тому

      I have a dedicated "Delegates and Protocols" video coming up soon, but probably won't go live for a week or two. In the meantime, I describe Delegates and Protocols using a Boss/Intern analogy in my video about UIButtons in TableView Cells here: ua-cam.com/video/UPrBXUWPf6Q/v-deo.html

    • @jelly1928
      @jelly1928 7 років тому

      Oh ok perfect, thank you

  • @biyootifuldev2012
    @biyootifuldev2012 4 роки тому

    in line 30, `var stolen ...` but class example uses `let stolen ...`, is there a difference btw those keywords in regards to class vs struct?

  • @dylanl9532
    @dylanl9532 4 роки тому

    I know these interview tips are pretty old. But can you do an iOS system design interview? For example, you are tasked to make an app for insurance claim, how would you set up your models, views, and controllers.

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

    Very useful: This is perfectly clear!

  • @nileshjdarji
    @nileshjdarji 5 років тому +1

    Nicely explained. Absolutely love it. I have currently enrolled in Ray Wenderlich Udemy course. The course is good but they have made it difficult for students like me to understand struct using the pizza restaurant analogy. Have you come across any good material that you recommend that can help solidify the struct, classes and computed properties in swift. I am sure I will like your recommendations. Thanks.

    • @seanallen
      @seanallen  5 років тому

      Try Paul Hudsons books here: gumroad.com/a/762098803

    • @nileshjdarji
      @nileshjdarji 5 років тому +1

      @@seanallen Thank you Sir. Really appreciate it.

  • @hojdog
    @hojdog 6 років тому +2

    I get why you would use a class if you want inheritance, but let's say you don't need inheritance. Do you have examples of why something should be reference type vs value type? A.k.a. with inheritance out of the picture, when should I use Class vs Struct?

    • @seanallen
      @seanallen  6 років тому

      If you don't need inheritance, and there's no need or reason to keep a reference to the object, then I would use a Struct.

  • @shawntaylor9509
    @shawntaylor9509 6 років тому

    I'm confused. Are you in essence making an object of the object?

    • @shawntaylor9509
      @shawntaylor9509 6 років тому

      If you have myMacbook = Macbook(initialize) and stolenMacbook = Macbook(initialize) and you change a property in either one of the objects, it doesn't affect one another. You can say I'm slightly confused.

    • @shawntaylor9509
      @shawntaylor9509 6 років тому

      Where would one use this code in a practical sense?

  • @prasadbetha2741
    @prasadbetha2741 5 років тому +1

    Example looks good.. keep posting thank you

    • @seanallen
      @seanallen  5 років тому

      Glad you enjoyed it Prasad!

  • @javierv.5210
    @javierv.5210 7 років тому +1

    Sean does this mean that myClassButton is the subclass? so it inherits the definitions from UIButton?

  • @MrMuh-ro3uq
    @MrMuh-ro3uq 4 роки тому

    Can i use
    Intger year
    Flaot colour
    instead of
    Var year
    Var colour
    ?????
    Because we haven't used the term var yet (we use for example intger or flaot or char)

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

    Great explanation!!👍🏿

  • @MovingOutMyMoms
    @MovingOutMyMoms 5 років тому +1

    Great analogy Sean.

    • @seanallen
      @seanallen  5 років тому

      Glad you liked it 😀

  • @gabir1212
    @gabir1212 5 років тому

    Thanks, that was a very well explained point.

  • @sergeirodin7847
    @sergeirodin7847 4 роки тому

    Hello Sean. Please help me. Nested or not nested structures? which practice is better?

    • @seanallen
      @seanallen  4 роки тому +1

      They are fine. As always... it depends on the situation and how they are used.

    • @sergeirodin7847
      @sergeirodin7847 4 роки тому

      @@seanallen, thanks for the answer!

  • @quangminhha850
    @quangminhha850 Рік тому

    Stolan and myMac are both constants, how come we can change its properties?😢

  • @MrMuh-ro3uq
    @MrMuh-ro3uq 4 роки тому

    Can you give me a clear formula or logic question for this program, and as an example of that question, for example, a man who has an iPhone, an Asu color, and a version 7 that was stolen, I calculate that by using the class ..... I want such a question, but formally and understandably from your presence

  • @nvandijk5816
    @nvandijk5816 5 років тому

    Hey Sean, thank you for creating these simple and understandable videos! There are really easy to follow and nice to watch! With reference to this one, there was a question that didn't leave my mind.. It is related to one of your previous videos in which you explain the difference between let and var. My question is, why does the compiler not scream that the stolenMacBook variable is a constant (let) but its property color is modified in the next line..? Thank you in advance and please carry on making these videos!

  • @_Forever555
    @_Forever555 5 років тому +1

    Excellent explanation! Thank you!

  • @MasteRock87
    @MasteRock87 6 років тому

    Is that why you made stoleniPhone as var rather than a let, is because it's a value typed whereas stolenMacbook is a reference type os you defined it as a let??

  • @vinayaktudayekar9439
    @vinayaktudayekar9439 6 років тому +1

    Great video.thanks a lot sean

    • @seanallen
      @seanallen  6 років тому

      Glad you liked it, Vinayak.

  • @happie88
    @happie88 7 років тому +2

    Class - ByRef and Struc - ByVal.... yes!!!! :)

  • @alsonick
    @alsonick 4 роки тому +1

    This helped so much, thank you!

  • @chalkl3y
    @chalkl3y 7 років тому +1

    Great, clear explanation.

  • @TheDeeStain
    @TheDeeStain 6 років тому +1

    I love you haha such a basic concept but confused me so hard

    • @seanallen
      @seanallen  6 років тому

      Happy to hear it helped 👍

  • @MatthewBrown14827
    @MatthewBrown14827 6 років тому

    excellent but can we slow down because it feels like your going a million miles an hour to get it in 7:34

    • @seanallen
      @seanallen  6 років тому +1

      Hey Matthew, this was one of my earlier videos. I've improved my pacing a lot since then.

  • @MANJEET19891189
    @MANJEET19891189 4 роки тому

    do u have a Flight to catch?

    • @seanallen
      @seanallen  4 роки тому

      Not anymore.

    • @MANJEET19891189
      @MANJEET19891189 4 роки тому

      @@seanallen so be little slow while you speak.. that makes us easy to grasp! Thanks

    • @seanallen
      @seanallen  4 роки тому +1

      I've worked a lot on that. This video series is from when I first started my UA-cam channel. My recent videos are a lot better.

  • @aniltodakar6449
    @aniltodakar6449 6 років тому +1

    Good Explanation, Thank You.

    • @seanallen
      @seanallen  6 років тому

      Happy to help, Anil!

  • @sudarshanderangula4819
    @sudarshanderangula4819 6 років тому +1

    Make a videos on enums.
    Thanks in advance..

    • @seanallen
      @seanallen  6 років тому

      It's on the to-do list. SO many videos, so little time...

    • @sudarshanderangula4819
      @sudarshanderangula4819 6 років тому +1

      Sean Allen Thanks for responding sir...

  • @MantuKumar-in2qq
    @MantuKumar-in2qq 5 років тому +1

    Nice tutorial sir

  • @nirbarzilay6947
    @nirbarzilay6947 4 роки тому

    Great explanation! thanks

  • @dewas6237
    @dewas6237 4 роки тому

    hello, sean I love your tutorial thanks for help!