Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMark El-Lamaa
1,634 PointsCan someone please define these terms
Can someone define these terms so that I and many others like me can fully understand what is meant by: -Structs -properties -classes -objects Thank You
1 Answer
Jason Wayne
11,688 Points- Objects
Swift, objective-C and some other languages are called object-oriented programming, which means, it is based on objects rather than logic. An object contains both data(state) and code (behaviour)
Though it may not be the best way to think of it, try to think of Objects in programming as things that can be found in the real world
Try checking out object oriented programming definition
- Properties
related to understanding about Objects. An object basically encapsulates data via its properties
Easy way to think of it is that, properties are characteristics. Imagine that you have a Car. That car is an Object. The brand of the car is BMW, and it is Blue in color. The brand of the car and the color is the properties of the car.
- Structs vs Classes
- The key difference as Apple states, structures are always copied when passed around in the code, while classes are passed around via reference
Example of class
var theName = NameClass(name: "Jimmy")
var theSecondName = theName ---> theName and theSecondName now has a reference of the same instance
theSecondName.name = "Steven"
println(theName.name) ---> this will equal to "Steven" println (theSecondName.name) ---> this will also equal to "Steven"
Example of Structs
var theMovieName = MovieNameClass(name: "Dark Knight")
var theSecondMovieName = theMovieName ---> theMovieName and theSecondMovieName are two structs that have the same value
theSecondMovieName.name = "The Social Network"
println(theMovieName.name) --> theMovieName.name will still equal to Dark Knight
println(theSecondMovieName.name) --> theSecondMovieName.name is NOT the same as the MovieName.name. It is The Social Network
Hopefully, that helps.