标签: nscompoundpredicate

NSCompoundPredicate

我正在尝试UITableView's使用UISearchDisplayController和过滤数据NSCompoundPredicate.我有一个3的自定义单元格UILabels,我想在搜索中过滤所有内容,因此NSCompoundPredicate.

  // Filter the array using NSPredicate(s)

  NSPredicate *predicateName = [NSPredicate predicateWithFormat:@"SELF.productName contains[c] %@", searchText];
  NSPredicate *predicateManufacturer = [NSPredicate predicateWithFormat:@"SELF.productManufacturer contains[c] %@", searchText];
  NSPredicate *predicateNumber = [NSPredicate predicateWithFormat:@"SELF.numberOfDocuments contains[c] %@",searchText];

  // Add the predicates to the NSArray

  NSArray *subPredicates = [[NSArray alloc] initWithObjects:predicateName, predicateManufacturer, predicateNumber, nil];

  NSCompoundPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:subPredicates];
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时,编译器警告我:

不兼容的指针类型使用"NSPredicate*"类型的表达式初始化"NSCompoundPredicate*_strong"

我在网上看到的每个例子都是完全相同的,所以我很困惑.该NSCompoundPredicate orPredicateWithSubpredicates:方法采用(NSArray *)最后一个参数,所以我真的很困惑.

怎么了?

objective-c uisearchbar uisearchdisplaycontroller nscompoundpredicate

6
推荐指数
2
解决办法
7360
查看次数

Xcode 6.1中的NSCompoundPredicate错误

回到Xcode 6,在使用Core Data的项目中,我有以下几行.它工作正常.

fetchRequest.predicate = NSCompoundPredicate(type: .AndPredicateType, subpredicates: [predicate, datePredicate])
Run Code Online (Sandbox Code Playgroud)

谓词datePredicate属于NSPredicate类型.

昨天我更新到Xcode 6.1,现在上面这行给出了这个错误找不到成员'AndPredicateType'.像这样指定整个值NSCompoundPredicateType.AndPredicateType也不起作用.

然后我改变了行,使用下面的方便方法行.

fetchRequest.predicate = NSCompoundPredicate.andPredicateWithSubpredicates([predicate, datePredicate])
Run Code Online (Sandbox Code Playgroud)

现在我得到一个新错误无法将表达式的类型'()'转换为'NSPredicate?' .我不明白为什么.该文档未显示任何弃用或更改NSCompoundPredicate.

谁能告诉我如何纠正这个问题?

谢谢.

core-data ios nscompoundpredicate swift xcode6.1

2
推荐指数
1
解决办法
1595
查看次数

在swift 3中创建复杂的NSCompoundPredicate

我想在swift 3中创建一个复杂的NSCompoundPredicate,但是,我不知道如何做到这一点.

假设我有5个谓词(p1,p2,p3,p4,p5).我想实现以下条件:

compound1 = (p1 AND p2 AND p3) // NSCompoundPredicate(type: .and, 
                              //subpredicates: predicates)
compound2 = (p4 AND p5) // NSCompoundPredicate(type: .and, 
                       //subpredicates: predicates)
compound3 = (compound1 OR compound2) // problem is here

fetchRequest.predicate = compound3
Run Code Online (Sandbox Code Playgroud)

NSCompoundPredicate因为它的第二个参数获得了它不想要的NSPredicates数组.什么是最好的解决方案?

core-data nspredicate nscompoundpredicate swift

2
推荐指数
1
解决办法
486
查看次数