I have a question regarding variable scope with subclasses.
I have something like the following:
ParentClass.h
@interface ParentClass : NSObject
@property (nonatomic, strong, readonly) NSString *myIdentifier;
- (id)initWithIdentifier:(NSString *)identifier;
@end
ParentClass.m
@interface ParentClass()
@property (nonatomic, strong) NSString *myIdentifier;
@end
@implementation ParentClass
- (id)initWithIdentifier:(NSString *)identifier {
if (self = [super init]) {
self.myIdentifier = identifier;
}
return self;
}
@end
ChildClass.h
@interface ChildClass : ParentClass
- (NSString *)showMeTheIdentifier;
@end
ChildClass.m
@implementation ChildClass
- (NSString *)showMeTheIdentifier {
return self.myIdentifier;
}
Then I go to implement the class and I get no compiler warnings, but the result of the NSLog is (null)
ViewController.m
...
ChildClass *c = [[ChildClass alloc] initWithIdentifier:@"abc123"];
NSLog(@"What's my identifier? %@", [c showMeTheIdentifier]);
...
What am I doing wrong?
Thanks