Reputation: 9120
I have a core data model like this:
But I'm having problems trying to query all the names of the songs regarles of the albums or genre.
Any of you knows how can query all the songs in core data regardless of the album or genre?
I'll really appreciate your help.
Update:
NSManagedObjectContext *moc = [self managedObjectContext]; managedObjectContext];
NSEntityDescription *description = [ NSEntityDescription entityForName:@"Song" inManagedObjectContext:moc];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Song"];
request.entity = description;
NSError *error = nil;
NSArray *results = [moc executeFetchRequest:request error:&error];
The results array is empty. any of you knows why or what I'm doing wrong?
Upvotes: 0
Views: 69
Reputation: 80265
Your fetch looks fine (just skip the entity description). Step through the code and make sure:
nil
executeFetchRequest
is not nil
but an NSArray
cd
to the documents folder and examine the sqlite file with the sqlite3
command line tool. Check that the records you are expecting are there. If it works, it might be a problem with the display of your data rather than the retrieval.
Upvotes: 1
Reputation: 5590
Just create a fetch request for that CoreData model and execute the fetch
NSFetchRequest *request= [NSFetchRequest fetchRequestWithEntityName:@"Song"];
Upvotes: 0