我正在尝试使用NSPredicate过滤数组中的一些fetchedobjects(大量联系人)。谓词采用一组id,如(2,3,4,5,6,5,000),并且应该找到所有的情况,其中fetchedObjects或联系人数组中的联系人中的uid出现在id列表中
我的过滤器应返回一些对象,但返回0.有人可以建议代码可能出错吗?它可能是NSPredicate还是我的数组有问题?
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.uid IN %@", uids];
NSMutableArray *array = [[NSMutableArray alloc]initWithArray:fetchedObjects];
//No objects though there should be some
NSArray<Contacts*>* mycontacts = [array filteredArrayUsingPredicate:predicate];
感谢您的任何建议。
编辑:
我正在寻找一个NSPredicate
,它会返回fetchedObjects
中uid
数组uids
中uid
的所有对象。例如,如果我在数组中有三个对象,如下所示,我希望谓词返回前两个在数组中找到uid
(2或3)的对象(2,3,4) ,5,6,5,000)但不返回数组中不存在uid|first|last
2|Bob|Jones
3|Mary|Smith
333|John|Doe
(333)的第三个:
NSArray<Contacts*>* mycontacts
编辑2:
Fetched对象是一个联系人数组,我认为是从fetchedResultsController创建的,它已经从Core Data执行了托管对象的提取。我尝试使用语法 NSEntityDescription *entity = [NSEntityDescription entityForName:@"Contacts" inManagedObjectContext:context];
NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
NSError *error = nil;
if (![fetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
// abort();
}
NSArray *fetchedObjects = fetchedResultsController.fetchedObjects;
对数组进行排序,但也许我做错了...
if(empty($_FILES['verifyfile']['name']))
{
$path = 'No';
}
else
{
$name = $_FILES['verifyfile']['name'];
$tmp = $_FILES['verifyfile']['tmp_name'];
$path = "files/".basename($currentdatetime.$name);
move_uploaded_file($tmp,$path) ; // Moving Uploaded file