2
votes

Error ::: 2012-11-07 16:07:31.360 Random Date[1100:c07] -[NSManagedObject name]: unrecognized selector sent to instance 0x6b77240 2012-11-07 16:07:31.363 Random Date[1100:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject name]: unrecognized selector sent to instance 0x6b77240' * First throw call stack: (0x1793022 0x1193cd6 0x1794cbd 0x16f9ed0 0x16f9cb2 0xed0a57 0xed05e4 0xed00b0 0xecf45d 0xecd2fd 0x316e 0x3481 0xdea1e 0xddfec 0x104f1d 0xef1cb 0x105df1 0x105e0d 0x105ea9 0x446f5 0x4473c 0x234f 0x15386 0x16274 0x25183 0x25c38 0x19634 0x167def5 0x1767195 0x16cbff2 0x16ca8da 0x16c9d84 0x16c9c9b 0x15c65 0x17626 0x1ffd 0x1f65 0x1) terminate called throwing an exception

Main Code Listed Below.

{



RootViewController *rvc = [[RootViewController alloc] init];

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:rvc];
[[self window] setRootViewController:nc];
[rvc setManagedObjectContext:[self managedObjectContext]];


self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

IN ROOTVIEWCONTROLLER

enter code here
-(void)addNewRandomDate
{

NSManagedObject *newRandomDate = [NSEntityDescription insertNewObjectForEntityForName:@"RandomDate"
                                                               inManagedObjectContext:managedObjectContext];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateFormat:@"EEEE"];

NSDate *date = [NSDate dateWithTimeIntervalSince1970:arc4random()];
NSString *dayName = [dateFormatter stringFromDate:date];

[newRandomDate setValue:date forKey:@"date"];
[newRandomDate setValue:dayName forKey:@"dayName"];

NSError *error = nil;
BOOL success = [managedObjectContext save:&error];
if (!success) {

    NSLog(@"Error = %@", error);
}

[self fetchRandomDates];
}
1
It would be helpful to the community if you could add to your question to explain what you're trying to achieve, what you think caused the error and any steps you've already taken to resolve the issue. But Welcome! - edparry
I can't see managedObjecttContext = [[NSManagedObjectContext alloc]init]; Did you create it in some place of your code? - Giuseppe Mosca
the managedObjectContext had been initialised at AppDelegate.m provided by the core-data template. Which was set by the [RootViewControler setManagedObjectContext:[self managedObjectContext]] ... property of managedObjectContext of RootViewController has been declared already from the RootViewController file.. I need helllpppppp... - moses

1 Answers

2
votes

Reason to Exception throw was: Using the insertNewObjectForEntityForName:@"RandomDate" inManagedObjectContext:managedObjectContext in the FecthresultControllern instead of using enityForname: InManagedObjectContext ...