Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 21, 2012, 01:59 PM   #1
larswik
macrumors 65816
 
Join Date: Sep 2006
So about Singeltons and Global ivars.

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!
__________________
I know more than yesterday.
Lars
larswik is offline   0 Reply With Quote
Old Apr 21, 2012, 06:03 PM   #2
xStep
macrumors 68000
 
Join Date: Jan 2003
Location: Lost in Minneapolis
Quote:
Originally Posted by larswik View Post
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.
__________________
My App: CameraTime - Time lapse photography for novice and advanced users.
xStep is offline   0 Reply With Quote
Old Apr 21, 2012, 11:15 PM   #3
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 2006
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.
__________________
I know more than yesterday.
Lars
larswik is offline   0 Reply With Quote
Old Apr 22, 2012, 10:53 AM   #4
xStep
macrumors 68000
 
Join Date: Jan 2003
Location: Lost in Minneapolis
Quote:
Originally Posted by larswik View Post
So instance variables are also know as global variables, to that object.
Yes, but nobody refers to them as global to the object because global indicates more than that. People refer to them as instance variables, or ivars in short form.
__________________
My App: CameraTime - Time lapse photography for novice and advanced users.
xStep is offline   0 Reply With Quote
Old Apr 22, 2012, 12:35 PM   #5
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 2006
Cool. Thank you.
__________________
I know more than yesterday.
Lars
larswik is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
It must be global warming!!! tshrimp Politics, Religion, Social Issues 73 May 28, 2013 09:32 PM
Help again :( Global Variables. resetme iPhone/iPad Programming 14 Dec 28, 2012 03:20 PM
Global imessage? frunkis54 iPhone 8 Jul 14, 2012 10:19 AM
Functions, classes and ivars jivaro Mac Programming 6 Jun 10, 2012 03:26 PM
VZW Galaxy S3 will have Global LTE! Will the iphone 5 have Global LTE also? PacificBeach iPhone 34 Jun 7, 2012 02:07 PM

Forum Jump

All times are GMT -5. The time now is 12:11 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC