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 trialHarry Stromfelt
2,985 PointsWhat is the benefit of making variables an @property? When is it ok not to/better to?
The title has the question, but I noticed in the tutorial that Ben says "we'll use the currentUser a lot, so let's actually make it a property" this made me wonder why we sometime leave it out etc.
Thanks
1 Answer
Stone Preston
42,016 Pointsif you store the value of the current user in a property, you can just reference that property anytime you need the current user instead of having to call [PFUser currentUser] all the time.
Harry Stromfelt
2,985 PointsHarry Stromfelt
2,985 PointsOk I sort of get it, if you didn't declare it as a property then even if you made a currentUser variable within the scope of a function it couldn't be called elsewhere. What would happen if you did PFUser *currentUser = [PFUser currentUser]; in the viewDidLoad bit? Would that also only exist during the viewDidLoad call?
Alternatively, with methods, do we always have to declare them in the header file, and if not when is ok to leave it out?
Thanks!
Stone Preston
42,016 PointsStone Preston
42,016 Pointsthat currentUser variable only exists in the scope of viewDidLoad. you could not access it anywhere else except inside viewDidLoad
if you want method to be seen/available in other classes then you need to declare them in the header file. if they are not in the header and you try to call the method outside of the class itself it wont know it exists. So if you are planning on calling that method somewhere other than the class file itself, it needs to be in the header.