0
當使用nspredicate時(謂詞之間)我有一個異常。謂詞之間的問題
有我使用的代碼:
NSMutableArray *returnedArray=[[[NSMutableArray alloc]init] autorelease];
NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *objEntity = [NSEntityDescription entityForName:@"Note" inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:objEntity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"When" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
[sortDescriptor release];
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:
@"self.Reunion==%@",reunion];
NSNumber *endOfEtape=[NSNumber numberWithInt:[etape.positionDepart intValue]+[etape.duree intValue]];
NSExpression *s1 = [ NSExpression expressionForConstantValue: etape.positionDepart ];
NSExpression *s2 = [ NSExpression expressionForConstantValue: endOfEtape ];
NSArray *limits = [ NSArray arrayWithObjects: s1, s2, nil ];
NSPredicate *predicate2=[NSPredicate predicateWithFormat: @"self.When BETWEEN %@",limits];
NSPredicate *predicate=[NSCompoundPredicate andPredicateWithSubpredicates:
[NSArray arrayWithObjects:predicate1,predicate2,nil]];
[fetchRequest setPredicate:predicate];
NSArray *notes;
notes=[context executeFetchRequest:fetchRequest error:nil];
[fetchRequest release];
,我不得不在其上我稱之爲「executeFetchRequest:」行的「objc_exception_throw」方法。
如果你能幫助我,我會很高興。 謝謝。
positinDepart和endOfType是NSNumbers 所以我想我應該做的nstring包含兩個 –
的值,你可以使用%d並獲取NSNumber的intValue ...無論如何它需要拆箱。 –