Hello everyone, I have an issue that I cannot figure out, been at it for quite some time now.
My goal is to populate a NSMutableArray and save it to core data and retrieve it. My tableview is being populated correctly , i.e. I am using Group and populating the titleForHeaderInSection. But when I terminate the app and try to do a Fetch and cast to an NSMutableArray the data is unreadable and my app is crashing.
This is my NSMutableArray *sectionNames , what it looks like after being populated.
The NewObject has this in it <Car_Doc_Safe_Plus.CarName: 0x7fc2226cf080> (entity: CarName; id: 0xd000000000080000 <x-coredata:/
carsname = "(\n Ram,\n Jeep\n)";
relationship = nil;
This is my Termination when I try to Fetch. *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Car_Doc_Safe_Plus.CarName length]: unrecognized selector sent to instance 0x7fd783ce3130'
This is my save to Core Data; My entity is set up to receive NSString , I also tried - transformable - with no luck.
-(void) saveToCoreData {
NSError *error;
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = appDel.managedObjectContext;
_entity = [NSEntityDescription entityForName:@"CarName" inManagedObjectContext:context];
NSManagedObject *newObject =[[NSManagedObject alloc]initWithEntity:_entity insertIntoManagedObjectContext:context];
NSString *saveString = [[NSString stringWithFormat:@"%@",sectionName]mutableCopy];
[newObject setValue:saveString.stringByStandardizingPath forKeyPath:@"carsname"];
[context save:&error];
}This is my Fetch in ViewDidLoad...
AppDelegate *appDel = [UIApplication sharedApplication].delegate;
NSManagedObjectContext *context = appDel.managedObjectContext;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"CarName" inManagedObjectContext:context];
[request setEntity:entity];
NSError *error = nil;
NSMutableArray *results = [[context executeFetchRequest:request error:&error]mutableCopy];
NSString *tempString = [NSString stringWithFormat:@"%@",results];
sectionName = [[NSMutableArray arrayWithArray:result]mutableCopy;]If I do an NSLog it looks like this for the tempString ....
The Temp-Data-String has this in it (
"<Car_Doc_Safe_Plus.CarName: 0x7fd783cbd000> (entity: CarName; id: 0xd000000000040000 <x-coredata:/
"<Car_Doc_Safe_Plus.CarName: 0x7fd783ce3130> (entity: CarName; id: 0xd000000000080000 <x-coredata://5F052E60-F5D2-4129-9955-537074450B8B/CarName/p2> ; data: <fault>)"
This is works perfectly on first population of my NSMutableArray *sectionName , but when the Fetch request happens the app crashes.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [sectionName objectAtIndex:section];
}Any help / guidance is greatly appreciated.
JZ