简体   繁体   中英

NSFetchedResultsController not work in Release mode

I develop a app using coredata.

But, in AdHoc or Release mode , cannot get data from coredata(using NSFetchedResultsController). In Debug mode, can get data.

look followin code.

NSFetchRequest *req = [[NSFetchRequest alloc] initWithEntityName:MODEL_NAME] ;
[req setFetchBatchSize:20] ;
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"orderIndex" ascending:YES];
[req setSortDescriptors:[[NSArray alloc] initWithObjects:sortDescriptor, nil]] ;
NSFetchedResultsController *res = [[NSFetchedResultsController alloc] initWithFetchRequest:req managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil] ;
NSAssert([res performFetch:nil], @"Fetch failed") ;
int dataCounter = [[[res sections] objectAtIndex:0] numberOfObjects] ;
// In Release mode:0, in Debug mode:2
NSLog(@"dataCounter:%d",dataCounter) ;

I change Release or Debug mode , like this way. Produce > Schema > Edit Scheme > Run > Build Configuration.

Env:Xcode 4.6.3 , Base SDK iOS 6.1

Do you have any help ?

Thank you.

NSAssert([res performFetch:&error], @"Fetch failed") ;

This code is wrong.

I setting Other C/C++ Flags "-DNS_BLOCKS_ASSERTIONS=1" in Release mode. this flag is to remove NSAssert line. So, performFetch is not exec.

thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM