Xcode 6.1中的NSCompoundPredicate错误



回到Xcode 6中,在一个使用Core Data的项目中,我有以下行。它运行良好。

fetchRequest.predicate = NSCompoundPredicate(type: .AndPredicateType, subpredicates: [predicate, datePredicate])

谓词日期谓词

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

然后我把行改为使用下面的方便方法行。

fetchRequest.predicate = NSCompoundPredicate.andPredicateWithSubpredicates([predicate, datePredicate])

现在我收到一个新错误无法将表达式的类型"()"转换为类型"NSPredcate?"。我不明白为什么。文档中也没有显示对NSCompoundPredicate的任何弃用或更改。

有人能告诉我如何纠正吗?

谢谢。

初始值设定项

extension NSPredicate {
    convenience init?(format predicateFormat: String, _ args: CVarArgType...)
}

现在是一个故障初始化器。它返回一个可选的NSPredicate?以打开结果(或使用可选绑定)。例如:

let compoundPredicate = NSCompoundPredicate(type: .AndPredicateType, subpredicates: [predicate!, datePredicate!])
// Or:
let compoundPredicate = NSCompoundPredicate.andPredicateWithSubpredicates([predicate!, datePredicate!])

参考文献:

  • Swift博客:https://developer.apple.com/swift/blog/?id=17
  • Swift文档:https://developer.apple.com/library/ios/documentation/swift/conceptual/Swift_Programming_Language/Declarations.html

相关内容

  • 没有找到相关文章

最新更新