Variables declared in @implementation

I am working on a list of code from a book and has a couple of variables (in particular, NSString *) declared and initialized in @implementation, not @interface, but outside of any method body. I have not seen this before, and I wonder what the difference is in scale, etc.

I had a quick look at the Objective-C programming language, but I don't see anything describing what it is.

thank

Andy

+3
source share
1 answer

Variables declared inside @implementation have a global scope.

If you declare them as β€œstatic,” they are only visible from methods in the same source file.

So:

@implementation MyClass

NSString *myString; // global scope, and accessible by all code in your project

or

@implementation MyClass

static NSString *myString; // global scope, but only accessible by code 
                           // in this source file
+7
source

Source: https://habr.com/ru/post/1750488/


All Articles