Is there a way to pass a variable from class to class? I have an app that has different views (each with its own .m and .h file), and I'd like to pass an integer from one class to another, in this case being an int that an NSTimer increments by 1.
Is there a way to pass a variable from class to class? I have an app that has different views (each with its own .m and .h file), and I'd like to pass an integer from one class to another, in this case being an int that an NSTimer increments by 1.
How can I do that?
Thanks,
Dutchman
Look up the singleton design pattern. A singleton data container object works beautifully for sharing data between classes.
A singleton is an object that only gets created once. It has a class method that returns a pointer to itself. The implementation of the class method might look like this:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Look up the singleton design pattern. A singleton data container object works beautifully for sharing data between classes.
A singleton is an object that only gets created once. It has a class method that returns a pointer to itself. The implementation of the class method might look like this:
There are lots of examples of singletons in Cocoa: Apple typically calls the class method to return a singleton shared<classname>.
Examples: NSUserDefaults sharedUserDefaults, NSFileManager sharedDataManager, etc, etc.
Thanks, but this seems way too hard. Is there an easier way? BTW, I don't get the point of using @property. What are they? You seem like a good mentor. Please help me!
Also some other unrelated questions:
What's the point of the #define ?
What does the _ifdef thing do?
In english, what is the + operator for the class method? I have no idea what that means.
Thanks, but this seems way too hard. Is there an easier way? BTW, I don't get the point of using @property. What are they? You seem like a good mentor. Please help me!
Also some other unrelated questions:
What's the point of the #define ?
What does the _ifdef thing do?
In english, what is the + operator for the class method? I have no idea what that means.
Thanks,
Dutchman
Sigh.
It sounds like you don't know anything at all about Objective C. It's not practical to teach it to you in a forum. You need to buy a good book on Objective C and do some self-study. There are also some good online guides.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Alright. Now coming back to what I posted before, I realize I was a complete N00B. Anyways, one question: If I have a method, lets say burp:
Code:
-(int)burp:(int)times{
//have some timer
return times;
}
Can that variable that is returned be constantly updated? Like if I have a timer and I want to increment an integer every second, in my secondary class, can that instance variable be constantly changed? Or once the instance is called, then the variable is static?