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 trialKerem Donmez
7,149 PointsVariable declaration before viewDidLoad
What happens if I declare the value of a variable before viewDidLoad and use it somewhere in that class? İt might be a stupid question but I currently don't have a mac book and just can't try it out so if someone can tell me I would appreciate it.
1 Answer
Stone Preston
42,016 Pointsyou can do that. that would be whats known as an instance variable or ivar:
@implementation MyClass {
// declare it here
NSString *myVariable;
}
// methods go here
// you can access myVariable within the class implementation
@end
Kerem Donmez
7,149 PointsKerem Donmez
7,149 PointsThanks for the reply, but it seems I forgot some stuff in my question.I know instance variables , I was trying to ask what would happen if you also set its initial value there before where It is usually set, in viewDidLoad. Then try to access it without touching it in viewDidLoad.
Stone Preston
42,016 PointsStone Preston
42,016 Pointsyou can do that
Kerem Donmez
7,149 PointsKerem Donmez
7,149 PointsOk, thank you.