我試圖使用NSPredicate
只獲取特定的對象。問題是所有的對象都被提取,並且它只應該是條件正確的特定對象。NSPredicate返回所有對象
- (void)fetchDevices {
// Fetch the devices from persistent data store
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Songs"];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Songs" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// retrive the objects with a given value for a certain property
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"selectedRow == %@" , selectedRowNumber];
devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
[fetchRequest setPredicate:predicate];
}
的selectedRowNumber
是在.h
文件中聲明的int
。
在我的歌實體一看:
PS。如果需要更多信息,請在下面留言,我會提供。
您可以使用''==或'='謂詞中,它沒有任何區別。 –
很酷。感謝您的高舉。 –