Lefora Free Forum
login join
Loading
360 views

Application initialization and variable scope

Page 1
1–2
rookie - member
6 posts

G'day all,

Apologies for the newbie question.  I'm teaching myself Xcode and making haste slowly.  The question is this: I want to initialize a variable (an NSMutableString) when the application opens then access it from from my controller.m file linked to my GUI.  I have figured out that I can stick the declaration in main.m but not sure how to see the variable from controller.m and modify it.

Can anyone enlighten me?

Cheers,
A.

?
288 posts

Well, remember that Obj/C is C - so extern and all that kind of thing works.  You could do:

in main.m
extern NSMutableString* myString ;
NSMutableString* myString ;

int main(bla bla)
{
    myString = [[NSMutableString alloc]stringWithFormat:@"bla bla", whatever] ;

}

in Controller.m
extern NSMutableString* myString

.... and myString will be available in Controller.h

A couple of points:
1) Extern are usually declared in .h files and #include to 'pull them in'
2) Extern is a singleton (there's one myString in the whole program)

Robin

__________________
Page 1
1–2

Locked Topic


You must be a member to post in this forum

Join Now!