Core Data confusion: fetch without tableview.
        Posted  
        
            by Mr. McPepperNuts
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mr. McPepperNuts
        
        
        
        Published on 2010-06-03T17:25:59Z
        Indexed on 
            2010/06/03
            17:44 UTC
        
        
        Read the original article
        Hit count: 325
        
iphone
|objective-c
I have completed and reproduced Core Data tutorials using a tableview to display contents. However, I want to access an Entity through a fetch on a view without a tableview. I used the following fetch code, but the count returned is always 0. The data exists when the database is opened using SQLite tools.
    NSManagedObject *entryObj;
XYZDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *managedObjectContext = appDelegate.managedObjectContext;
NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Quote" inManagedObjectContext:managedObjectContext]; 
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"id" ascending:YES];  
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];   
[request setSortDescriptors:sortDescriptors];
[request setEntity: entity]; 
NSArray *results = [managedObjectContext executeFetchRequest:request error:nil];
if (results == nil) {
    NSLog(@"No results found");
    entryObj = nil;
}else {
    NSLog(@"results %d", [results count]);
}
[request release];
[sortDescriptors release];  
count returned is always 0; it should be 5.
Can anyone point me to a reference or tutorial regarding creating a controller not to be used with a tableview.
© Stack Overflow or respective owner