I have declared a global variable like below
extern NSString *name;
@interface viewcontrollerOne{}
in implementation file i am accessing that global variable in some method like
-(void)someMethod
{
name = @"hello";
}
but this is giving linker error.
“name”, referenced from:
-[viewcontrollerOne someMethod] in viewcontrollerOne.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The following is merely a declaration:
It declares there is a symbol of
NSString*namedname. It does not create storage.To do that, you will need to provide a definition for
name. To do this, add the following to your .m file:If you want to set it in an instance method, as seen in your example, then you can declare it:
MONFile.h
Define it:
MONFile.m
then you can write
name = @"hello";in your instance method.