Okay I won't pretend to know everything about Objective-C and iOS programming, as I'm just getting started, but this one has me completely stumped. I have a class, ShoppingListViewController, and in that class, I override the initWithCoder Method to read:
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self.title = @"Shopping List";
[self loadItems];
}
return self;
}
Within that loadItems method, there is a line that causes the app to crash on opening every time:
self.items = [NSMutableArray array];
The app crashes with the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Could not load NIB in bundle:
However if I replace that line with the following:
_items = [NSMutableArray array];
Everything works fine. Now I understand that I am circumventing the default setters by doing this, but I'm unclear on why exactly the runtime has an issue with this normally, and why it's anything to do with NIB files? Could anyone enlighten me?
Updating with more info:
The items property is declared in the header of the class:
@property (nonatomic) NSArray *items;
And the loadItems method is pretty sparse and essentially that line is the only one that really matters on first load:
- (void)loadItems {
NSString *filePath = [self pathForItems];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
self.items = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
} else {
_items = [NSMutableArray array];
}
}