Since the .m files for the foundation classes(say for NSString) are not available , I was thinking if I could declare an extension, inside the .m file of a category declared on the same class. I was successful in creating a private method which doesn't use any instance variable inside. But when I tried to access an iVar declared inside the interface its causing problems.
*This didn't have a purpose as such, was just trying out things.
What I did was declare a category on NSString
:
NSString+TestInterface.h
@interface NSString (TestInterface)
@end
NSString+TestInterface.m
@interface NSString () {
NSString *myVar;
}
@property (strong) NSString *myVar;
-(void)myPrivateMethod;
@end
@implementation NSString (TestInterface)
-(void)myPrivateMethod{
myVar=@"random";
// [self setValue:@"check" forKey:@"myVar"];
NSLog(@"Private %@",myVar);
// NSLog(@"Private %@",[self valueForKey:@"myVar"]);
}
@end
When I do it this way I get the following compiler error:
Undefined symbols for architecture x86_64:
"_OBJC_IVAR_$_NSString.myVar", referenced from: -[NSString(TestInterface) myPrivateMethod] in NSSTring+TestInterface.o ld: symbol(s) not found for architecture x86_64
Can someone tell me what is happening?