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 trial
Mark El-Lamaa
1,634 PointsCan someone explain what setters and getters are used for in Swift for iOS, without a lot of complicated language please
Thanks
1 Answer
Jason Wayne
11,688 PointsFirstly, setter and getter isn't just related to Swift, it's an object oriented programming thing. You can find this in Java, Objective-C too.
Setter = a method which gets called every time when property value is changed
Getter = a method that gets called every time you access the property
Different language have different ways to implement setter and getters. But the whole idea of it is basically a function that is used in object oriented programming to get and set values of a property.
Hope that helps. =]
Mark El-Lamaa
1,634 PointsMark El-Lamaa
1,634 PointsThanks for that, can i now ask why the methods get called when a property is changed/ accessed