For a long time I have been using 1 and 3 below, and more recently 4 to define my variables.
However I have noticed that there are other valid definitions that my be new to Objective-C 2 and that would make code look nicer by keeping methods and their internal variables together.
Could someone please verify the assertions in the comments?
static id var1; // 1. Shared among all classes and their instances defined in this file
id var2; // 2. Same as 1?
@implementation MyClass
{
id var3; // 3. Different variable for each instance
}
- (void)method
{
static id var4; // 4.1. Not accessible from other methods
// 4.2. Different for each instance?
}
id var5; // 5. Same as 3? Same as 1/2?
static id var6; // 6.1. Same as 1?
// 6.2. Not visible to other classes in this file?
@end
A couple of questions like this one are kinda similar but Objective-C may have some differences.