normally I hate going to people much more seasoned than I am at a programming language and try to gut it out, but I've been scratching my head over this one for quite some time. It's the ever popular
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* - [__NSArrayMutable .. insertObject:atIndex:]: object cannot be nil
I'm quite new to Xcode/Obj-C, so my understanding is limited. Essentially, I've been trying to modify Apple's 'Your Second iOS App' to better understand how everything is working together. The app is basically a modified version of their "BirdSighting" app. I checked this awesome site and found no concise answers for my answer in particular.
Anyways, I have added the exception breakpoints and it is throwing at the line:
[self.masterNewEventList addObject:event];
towards the bottom.
NewEventDataController.m
#import "NewEventDataController.h"
#import "NewEvent.h"
@interface NewEventDataController ()
- (void)initializeDefaultDataList;
@end
@implementation NewEventDataController
- (void)initializeDefaultDataList
{
NSMutableArray *eventList = [[NSMutableArray alloc] init];
self.masterNewEventList = eventList;
NewEvent *event;
NSDate *today = [NSDate date];
event = [[NewEvent alloc] initWithName:@"Event" date:today];
[self addNewEventWithEvent:event];
}
- (void)setMasterNewEventList:(NSMutableArray *)newList
{
if (_masterNewEventList != newList)
_masterNewEventList = [newList mutableCopy];
}
- (id)init
{
if (self = [super init])
{
[self initializeDefaultDataList];
return self;
}
return nil;
}
- (NSUInteger)countOfList
{
return [self.masterNewEventList count];
}
- (NewEvent *)objectInListAtIndex:(NSUInteger)theIndex
{
return [self.masterNewEventList objectAtIndex:theIndex];
}
- (void)addNewEventWithEvent:(NewEvent *)event
{
[self.masterNewEventList addObject:event];
}
@end
My NewEvent.m is as follows:
#import "NewEvent.h"
@implementation NewEvent
-(id)initWithName:(NSString *)event date:(NSDate *)date
{
self = [super init];
if (self)
{
_event = event;
_date = date;
return self;
}
return nil;
}
@end
My line of thinking is that when it is trying to add the initial event (right before throwing), the event itself is not initialized properly. The debug reads:
event = (NewEvent *) 0x00000000
Thanks in advance for taking a look.
main.m
#import <UIKit/UIKit.h>
#import "ParentAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([ParentAppDelegate class]));
}
}