Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
So until the other day I thought my objects instance variables were "Global Variables". My thinking was that if I had 2 or more Methods that needed to access the same variable, I would declare them "Globally" and instantiate them. If not I would declare them locally within the Method for temporary use. (like I learned in my Pascal class regarding the Scope or variables).

- Are object instance variables also know as global variables for that object? I seem to use them in that capacity and they function that way. But are they know as Global Variables too?

I have not learned how to use Singletons yet but I guess they store information "Globally" in my root controller which I can use to pass information to my different objects?

- Are there any good tutorials out there to learn how to use Singletons? I did google it but sometimes folks here have good resources too. This is my weekend project to learn.

Thanks!
 

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
So until the other day I thought my objects instance variables were "Global Variables". My thinking was that if I had 2 or more Methods that needed to access the same variable, I would declare them "Globally" and instantiate them. If not I would declare them locally within the Method for temporary use. (like I learned in my Pascal class regarding the Scope or variables).

- Are object instance variables also know as global variables for that object? I seem to use them in that capacity and they function that way. But are they know as Global Variables too?

I have not learned how to use Singletons yet but I guess they store information "Globally" in my root controller which I can use to pass information to my different objects?

- Are there any good tutorials out there to learn how to use Singletons? I did google it but sometimes folks here have good resources too. This is my weekend project to learn.

Thanks!

Based on your question, Singletons, AppDelegates and top-level data looks like a good read.

For more put the following into Google: using singleton cocoa

Instance variables are global to an object, yes. It's that scope thing you mentioned.

Sometimes you'll find a variable defined above the @interface. Those variables are global but typically considered class variables.

For some more check out Objective-C Variable Scope and Storage Class.
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
Cool, thanks for the links. I will read up on them.

So instance variables are also know as global variables, to that object. Thanks for the clarification.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.