Swift Classes and Structures Explained

  Переглядів 75,768

Sean Allen

Sean Allen

7 років тому

The next topic in my series on iOS Interview questions is about Classes and Structures in Swift. This is a fundamental question in iOS development and I was asked about it a few times during phone screens. In this video I'll walk you through the differences between Swift classes and structs in an Xcode Playground.
iOS Dev Courses - seanallen.teachable.com/
This is part of a series of videos about iOS interview questions in Swift. Check out the overview where I list and briefly discuss all the topics that are in this series:
• iOS Interview Question...
Project Source Code:
www.dropbox.com/sh/b1mynrmk0m...
Apple Classes & Structs Documentation:
developer.apple.com/library/c...
iOS Dev Courses:
seanallen.teachable.com/
Twitter:
Sean Allen - / seanallen_dev
Hired.com:
hired.com/x/1n01g
Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):
Paul Hudson's Hacking With Swift:
gumroad.com/a/762098803
Donny Wals - Combine:
gumroad.com/a/909014131
Mark Moeyken’s SwiftUI Books:
www.bigmountainstudio.com/swiftui-views-book/fzc51
Objc.io Books (Thinking in SwiftUI & Advanced Swift):
gumroad.com/a/656585843
Ray Wenderlich Books:
store.raywenderlich.com/a/208...
#swift #softwaredeveloper #iosdeveloper

КОМЕНТАРІ: 272
@seanallen
@seanallen 4 роки тому
Watch Next - iOS Take Home Project - Job Interview Practice - Free Preview - ukposts.info/have/v-deo/hYN6mWiwbXyWxmw.html
@sulabhagarwal3697
@sulabhagarwal3697 7 років тому
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 років тому
Thanks! I've always been good at coming up with analogies to explain things in a relatable way. Thanks for watching!
@Belizianboi13
@Belizianboi13 6 років тому
Yea good job bro!
@bigmtnstudio
@bigmtnstudio 6 років тому
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 6 років тому
Sulabh Agarwal it’s called common sense ‘genius’
@michaelamiro6076
@michaelamiro6076 4 роки тому
Impressive 2 years later. Point driven home. Not just to the door. To the very heart of home.
@seanallen
@seanallen 4 роки тому
Glad it was helpful 😀
@thomasnn
@thomasnn 6 років тому
Simple and to the point. Exactly what I needed
@seanallen
@seanallen 6 років тому
Glad you enjoyed it, Thomas!
@tonylinfreedom
@tonylinfreedom 5 років тому
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 5 років тому
Thanks Tony! Glad you found it helpful.
@FaraazKhanTV
@FaraazKhanTV 4 роки тому
Awesome analogy, understood it from the beginning
@seanallen
@seanallen 4 роки тому
Happy to help!
@isaacclark9825
@isaacclark9825 6 років тому
Your videos on interview questions are what I like best. More please!
@seanallen
@seanallen 6 років тому
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!
@nicholasdimaria
@nicholasdimaria 3 роки тому
I was very confused about this subject until I found your video. Thank you for the great analogy and excellent lesson!
@seanallen
@seanallen 3 роки тому
Glad it was helpful!
@nileshjdarji
@nileshjdarji 5 років тому
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!
@GuitarreroDaniel
@GuitarreroDaniel 3 роки тому
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 3 роки тому
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!
@synagridas13
@synagridas13 6 років тому
Your teaching skills are godlike - can’t believe i only just came across your channel. Awesome stuff man, keep it up
@seanallen
@seanallen 6 років тому
Thanks! Glad you're enjoying the channel.
@synagridas13
@synagridas13 6 років тому
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!
@eminRoblack
@eminRoblack 6 років тому
Really well structured tutorials with fast explanations and info...tnx for this man, really helps a lot !
@seanallen
@seanallen 6 років тому
Glad you enjoyed it, EmiN!
@Dennisvm82
@Dennisvm82 6 років тому
Perfect! Very well explained, Sean. Really loving the short video tutorials :-) keep it up!
@seanallen
@seanallen 6 років тому
+Dennis van Mazijk glad you enjoy it Dennis!
@ezadens
@ezadens 6 років тому
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 6 років тому
Thanks Ezuu! Glad you finally understand the difference!
@joeyng7366
@joeyng7366 2 роки тому
simple yet great explanation!
@jonessmith8670
@jonessmith8670 5 років тому
Thank you very much! This is so clear!
@vishwasmukund
@vishwasmukund 6 років тому
Thanks man. Your content is effective. Much better than most paid coursera courses. Keep up the good work
@seanallen
@seanallen 6 років тому
Thanks Vishwas!
@ercborg
@ercborg 6 років тому
So clearly explained, thank you! Great examples.
@seanallen
@seanallen 6 років тому
Glad you enjoyed it, Emanuel!
@ivanpena7323
@ivanpena7323 7 років тому
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!
@harshtokas123
@harshtokas123 3 роки тому
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.
@seanallen
@seanallen 3 роки тому
Happy to help, Harsh!
@bathong188
@bathong188 2 роки тому
This is an amazing explanation. Thank you!
@sebbe4171
@sebbe4171 5 років тому
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 😀
@Utubeasiangirls
@Utubeasiangirls 2 роки тому
Right to the point with simple examples without any blah blah, you Da Man :D
@wizzl8513
@wizzl8513 5 років тому
Your channel is a goldmine, keep up the great work !
@seanallen
@seanallen 5 років тому
Thanks for the kind words!
@cineverseproductions
@cineverseproductions 3 роки тому
I think almost every video of yours have my comment of thanks. And again, thanks sean for the simple and best analogy. 😄👍
@samr.4692
@samr.4692 5 років тому
Great analogy, nice clarification! Thank you...
@noblify299
@noblify299 6 років тому
your the best teacher i ever had in ios teaching... hats off keep going Your the best
@seanallen
@seanallen 6 років тому
Thanks Shehin!
@thinkinting
@thinkinting 4 роки тому
the excel vs google sheets analogy is excellent!!! it makes me understand the topic instantly, unlike some other tutorials.
@seanallen
@seanallen 4 роки тому
Happy to help!
@joshuajean4683
@joshuajean4683 2 роки тому
Best analogy for the two, I got tripped on it in a book I bought and other videos. Thanks
@seanallen
@seanallen 2 роки тому
Glad it was helpful!
@davidconnelly
@davidconnelly Рік тому
Very nicely explained. I'm thinking about learning Swift. I'll be checking out your content more in the future, hopefully. Cheers!
@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 6 років тому
Although already said but once again i will say, your analogy is perfect here. It just got settled in my mind.
@seanallen
@seanallen 6 років тому
Glad you're enjoying the videos!
@Mongerops
@Mongerops 6 років тому
dear lord, this was the best explanation I have found even better than what my instructor could come up with!
@seanallen
@seanallen 6 років тому
Glad it helped!
@siddheshkadam136
@siddheshkadam136 2 роки тому
Thanks for the explanation ! nice Analogy !
@codechamp2599
@codechamp2599 5 років тому
this logic is fuc*** cool , magnificent i would never forget it from now
@seanallen
@seanallen 5 років тому
haha, thanks. Happy to hear it was helpful 👍
@kslazinski
@kslazinski 4 роки тому
Great video! Thanks for this. I understand and remember now :)
@jumancamacho
@jumancamacho 6 років тому
Thanks for the magnific explanation!
@seanallen
@seanallen 6 років тому
No problem, Juan! Glad you enjoyed it!
@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!
@markme7092
@markme7092 4 роки тому
I like this guy. He has wide & great knowledge. Thanks for good vid !
@seanallen
@seanallen 4 роки тому
Happy to help!
@eddielacrosse2
@eddielacrosse2 2 роки тому
You earned yourself a damn subscription for this video. Thank you for the great content!
@JasonMitchellAZ
@JasonMitchellAZ 6 років тому
Great analogy!
@DoubleCheapBurger
@DoubleCheapBurger 3 роки тому
Thanks a lot, dude! This is such an excellent example.
@misheruzinho
@misheruzinho Рік тому
This helped me a lot, thank you!
@seanallen
@seanallen Рік тому
Glad it helped!
@JamesEtallaz
@JamesEtallaz 2 роки тому
Very useful: This is perfectly clear!
@_Forever555
@_Forever555 4 роки тому
Excellent explanation! Thank you!
@seanallen
@seanallen 4 роки тому
Happy to help!
@alsonick
@alsonick 4 роки тому
This helped so much, thank you!
@seanallen
@seanallen 4 роки тому
Glad it helped!
@yashkhandha
@yashkhandha 4 роки тому
Google doc and emailing word doc analogy to references and values ! BANG ON !!!!!
@seanallen
@seanallen 4 роки тому
Glad you enjoyed that analogy, Yash!
@crusherw6873
@crusherw6873 4 роки тому
really made sense. excellent work!!! love it
@asmatarunnum3071
@asmatarunnum3071 6 років тому
Best video on classes and structs i came across.....
@asmatarunnum3071
@asmatarunnum3071 6 років тому
Efficietly clears the actual concept
@seanallen
@seanallen 6 років тому
Thanks Asma! Glad you enjoyed it.
@M8VXR
@M8VXR Рік тому
Great description
@rahafalhelo6974
@rahafalhelo6974 6 років тому
This is the best tutorial, thanks😍
@seanallen
@seanallen 6 років тому
Thanks Rahaf! Happy to hear it helped.
@ebubeawachie
@ebubeawachie 2 роки тому
Amazing explanation. Finally I get it.
@seanallen
@seanallen 2 роки тому
Glad it helped, Mark!
@neimsaci942
@neimsaci942 3 роки тому
Good explanation! Thanks! 👍🏻
@seanallen
@seanallen 3 роки тому
Glad it was helpful!
@dinerdyyawdie9986
@dinerdyyawdie9986 2 роки тому
Great explanation!!👍🏿
@martinmuldoon8166
@martinmuldoon8166 6 років тому
Thanks very much. Very clear now on use cases for Structs.
@seanallen
@seanallen 6 років тому
Glad you found it useful, Martin!
@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!
@gabir1212
@gabir1212 4 роки тому
Thanks, that was a very well explained point.
@seanallen
@seanallen 4 роки тому
Glad you liked it!
@TheDeeStain
@TheDeeStain 5 років тому
I love you haha such a basic concept but confused me so hard
@seanallen
@seanallen 5 років тому
Happy to hear it helped 👍
@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: ukposts.info/have/v-deo/jYCjdo6MjoaXl4U.html
@jelly1928
@jelly1928 7 років тому
Oh ok perfect, thank you
@lukassimkanin3509
@lukassimkanin3509 2 роки тому
What a great analogy!
@aniltodakar6449
@aniltodakar6449 6 років тому
Good Explanation, Thank You.
@seanallen
@seanallen 6 років тому
Happy to help, Anil!
@prasadbetha2741
@prasadbetha2741 5 років тому
Example looks good.. keep posting thank you
@seanallen
@seanallen 5 років тому
Glad you enjoyed it Prasad!
@jasper5016
@jasper5016 6 років тому
Very different analogy. Wonderful and useful video.
@seanallen
@seanallen 6 років тому
Glad you enjoyed it, A P. Glad to hear it helped.
@MovingOutMyMoms
@MovingOutMyMoms 4 роки тому
Great analogy Sean.
@seanallen
@seanallen 4 роки тому
Glad you liked it 😀
@chalkl3y
@chalkl3y 6 років тому
Great, clear explanation.
@seanallen
@seanallen 6 років тому
Thanks Jason!
@yenniferhurtado6546
@yenniferhurtado6546 Рік тому
Great tutorial! Thnxs
@TheDesiVoyager
@TheDesiVoyager 8 місяців тому
Thanks for the simplest and amazing explanation. I have 1 doubt, why are you using 'Let' for stolenMacBook but 'Var' for stoleniPhone ?
@GurjinderSingh-tf2dl
@GurjinderSingh-tf2dl 5 років тому
Thanks!. Can you explain when to use class and when to use struct?
@76antreas
@76antreas 4 роки тому
the best explanation ever!!!!
@seanallen
@seanallen 4 роки тому
Glad you liked it, Antreas.
@nirbarzilay6947
@nirbarzilay6947 4 роки тому
Great explanation! thanks
@seanallen
@seanallen 4 роки тому
Happy to help, Nir!
@vinayaktudayekar9439
@vinayaktudayekar9439 5 років тому
Great video.thanks a lot sean
@seanallen
@seanallen 5 років тому
Glad you liked it, Vinayak.
@happie88
@happie88 6 років тому
Class - ByRef and Struc - ByVal.... yes!!!! :)
@dewas6237
@dewas6237 4 роки тому
hello, sean I love your tutorial thanks for help!
@seanallen
@seanallen 4 роки тому
Happy to help!
@acja87
@acja87 5 років тому
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?
@rogerwprice
@rogerwprice 6 років тому
Nice analogy!
@seanallen
@seanallen 6 років тому
Thanks Roger!
@sergiobost4891
@sergiobost4891 3 роки тому
That was so easy to understand. Thanks Maybe you could explain the self. in another video
@seanallen
@seanallen 3 роки тому
Glad it was helpful! I've added the self keyword to my video to-d list.
@XKiTuX
@XKiTuX 6 років тому
thanks .absolutely great :)
@seanallen
@seanallen 6 років тому
Hey XKitUX, welcome to the channel! Glad you got value from the video. More on the way!
@lukasm4821
@lukasm4821 6 років тому
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 років тому
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.
@giorgimeqvabishvili8210
@giorgimeqvabishvili8210 Рік тому
Thanks a lot Sean
@seanallen
@seanallen Рік тому
Happy to help!
@rinayaneeraj
@rinayaneeraj 5 років тому
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 5 років тому
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.
@MrAdityakool
@MrAdityakool 5 років тому
Loved it!!
@seanallen
@seanallen 5 років тому
Happy to hear it!
@sandeepvk
@sandeepvk 6 років тому
crushed it ! thanks
@seanallen
@seanallen 6 років тому
Glad you liked it, Sandy!
@mrsswathi12
@mrsswathi12 6 років тому
Thank you Sean
@seanallen
@seanallen 6 років тому
Glad it helped, Swathi!
@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!
@ashshkapoor
@ashshkapoor 6 років тому
Sir, you nailed it! :D
@seanallen
@seanallen 6 років тому
Thanks Ashish! Glad you enjoyed it.
@ashshkapoor
@ashshkapoor 6 років тому
Was trying to quote the same thing on StackOverFlow question by someone. Then I saw this and gonna paste this link rather. :)
@HyperActive94
@HyperActive94 4 роки тому
great video Sean thnx a lot
@seanallen
@seanallen 4 роки тому
Glad it helped, Ziko!
@mryup6100
@mryup6100 5 років тому
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 5 років тому
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.
@MantuKumar-in2qq
@MantuKumar-in2qq 4 роки тому
Nice tutorial sir
@seanallen
@seanallen 4 роки тому
Thanks Mantu!
@TheMicheilsGrey
@TheMicheilsGrey 5 років тому
Isn't value types live in stack and reference in heap ? value types working more faster then reference types ?
@JJ-up4xt
@JJ-up4xt 4 роки тому
Thank you that was neat
@seanallen
@seanallen 4 роки тому
Glad you liked it!
@iosdevelopernishantchandwa5741
@iosdevelopernishantchandwa5741 6 років тому
you are great ,
@SevenDeMagnus
@SevenDeMagnus 5 років тому
Hi what about enum? Is that a reference type or a value type? Does it take advantage of inheritance? Thank you.
@seanallen
@seanallen 7 років тому
Struggling with the difference between classes and structs? Leave a question here, I'm happy to help.
@sathamhussain9299
@sathamhussain9299 6 років тому
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 6 років тому
Thanks Satham! Glad you enjoyed and got value from the video.
@HodaPanther
@HodaPanther 5 років тому
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.
@shirishkumbar3144
@shirishkumbar3144 4 роки тому
very helpful
@seanallen
@seanallen 4 роки тому
Happy to help!
@piyushsharma1638
@piyushsharma1638 5 років тому
nice and easy
@MrMuh-ro3uq
@MrMuh-ro3uq 3 роки тому
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)
@easthastings6919
@easthastings6919 2 роки тому
you are the best
@biyootifuldev2012
@biyootifuldev2012 3 роки тому
in line 30, `var stolen ...` but class example uses `let stolen ...`, is there a difference btw those keywords in regards to class vs struct?
@kiransonne7689
@kiransonne7689 4 роки тому
can we create instance optional object in a class like var name:String?
@nikhilbalthi9133
@nikhilbalthi9133 4 роки тому
thank you keep doing
@seanallen
@seanallen 4 роки тому
Happy to help!
@gregorymolette118
@gregorymolette118 5 років тому
Thx for vid
@seanallen
@seanallen 5 років тому
Happy to help, Gregory.
Data Classes in Python Are The New Standard
20:34
NeuralNine
Переглядів 65 тис.
In 10 Minutes This Room Will Explode!
10:00
MrBeast
Переглядів 49 млн
Swift Optionals - How to Unwrap (real examples)
14:20
Sean Allen
Переглядів 10 тис.
Swift API Calls for Beginners (Networking) - Async Await & JSON
25:35
Your App Will Get Rejected | New Privacy Rules - 2024
11:26
Sean Allen
Переглядів 26 тис.
Swift - Class vs. Struct Explained
7:28
Sean Allen
Переглядів 28 тис.
Two-Sum Problem - Swift Tutorial - iOS Interview Coding Challenge
17:33
How to use Lazy in Swift
9:56
Sean Allen
Переглядів 38 тис.
Swift - What to Ask Them? - iOS Interview Questions
13:31
Sean Allen
Переглядів 31 тис.
Java Classes & Objects
11:36
Keep On Coding
Переглядів 280 тис.
I7 2600K тест в играх и сравнение с AMD Ryzen
17:53
Я Создал Новый Айфон!
0:59
FLV
Переглядів 646 тис.
Broken Flex Repair #technology #mobilerepair
0:55
ideal institute aligarh
Переглядів 15 млн