iphone - with - swift generic enum



Difference between declaring static variable inside and outside the implementation context in Objective C? (1)

There is no difference between

@implementation ClassA

static NSString *str = nil;

.....

@end

and

static NSString *str = nil;

@implementation ClassA

.....

@end

They work the same way ...

Static variables help give the class object more functionality than just that of a "factory" producing instances; it can approach being a complete and versatile object in its own right. A class object can be used to coordinate the instances it creates, dispense instances from lists of objects already created, or manage other processes essential to the application. In the case when you need only one object of a particular class, you can put all the object's state into static variables and use only class methods. This saves the step of allocating and initializing an instance.

Possible Duplicate:
Where do I have to declare static variables?

I've seen code like

@implementation ClassA

static NSString *str = nil;

.....

@end

as well as

static NSString *str = nil;

@implementation ClassA

.....

@end

What's the difference if a static var is declared inside the @implmentation context vs outside





static