Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ElysianEagle

macrumors newbie
Original poster
Jun 29, 2009
7
0
so i'm trying to use Core Data for the iPhone OS 3.0. i'm new to iPhone programming (and programming on the mac with tools like XCode).

anyway, i'm trying to use NSFetchedResultsController to fetch some data but my program crashes giving me a "EXC_BAD_INSTRUCTION". when i check the console there's a message saying "message class sent to freed object=0x<some address>"

so i guess my code is trying to use some object that has been released, but i cant figure out which object!!

the offending code is this:

Code:
NSManagedObjectContext* mob = ((MyAppDelegate*)[[UIApplication sharedApplication] delegate]).managedObjectContext;	
	
	NSEntityDescription* entityDesc = [NSEntityDescription entityForName:@"Record" inManagedObjectContext:mob];
	
	[request setEntity:entityDesc];

//this is the line where the program crashes
	NSFetchedResultsController* frc = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:mob sectionNameKeyPath:nil cacheName:nil];

and i cant for the life of me figure out what the hell is going on??

when i replace that last line with this one:
Code:
NSError* error;
NSMutableArray* mutableArray = [[mob executeFetchRequest:request error:&error] mutableCopy];

it works just fine!!

any ideas?? thanks!
 
hmm ok never mind. i re-read the documentation and it said "the fetch request must have at least one sort descriptor"...duh!! i'll try that and get back.

thanks for reading tho!
 
ok so it appears that that was indeed the problem, and its been fixed.

but i cant figure out how to do what i initially set out to do. basically, my model consists of Record objects that store information abt a person, such as first name, last name, etc.

i want to use the NSFetchedResultsController to grab all of this data and break it down by sections, where there is one section for each letter of the alphabet.

so for instance if i had two records, one for John Smith and another for Andy McDonald, i want to have 2 sections, one with the header "J" and another with the header "A". the records would be shown in a table view under these sections, such that Andy McDonald would appear under the "A" section while John Smith would appear under the "J" section.

since my Record entity already has a field for the first name, i think it would be redundant to introduce another just to hold the first letter of the first name...but then how do i go about breaking it into sections??

ideas much appreciated!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.