Is there a way to synthesize setters / getters for class variables in Objective-C?
Typically, when you group a set of related variables that need to be accessed globally, you create a so-called Singleton:
What should an Objective-C singleton look like?
This means that you have one class-level method that returns a generic instance to you - so you have a call like this:
[MyClass sharedInstance].myProperty
Since the values ββyou store are instance variables of the true class, you can use normal properties, but all classes will work with the same shared data.
Note that some people don't like the use of singletons, you can read some caveats about practice:
But since you're already starting out with one integral singleton in iPhone development (an application delegate that anyone can access at any time), it doesn't hurt to make this technology easier to use if you're careful. Note that instead of creating a Singleton class, one alternative is to delegate the application to create one instance of the storage variables class and access it via the delegate ...
source to share
something like this goes in your header, after the interface:
@property (retain) NSString* caption;
then it happens directly inside the implementation:
@synthesize caption;
Check out this tutorial for more details: http://www.cocoadevcentral.com/d/learn_objectivec/
source to share