Xcode 6.1中的NSCompoundPredicate错误

Isu*_*uru 2 core-data ios nscompoundpredicate swift xcode6.1

回到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.

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

谢谢.

Mar*_*n R 7

初始化程序

extension NSPredicate {
    convenience init?(format predicateFormat: String, _ args: CVarArgType...)
}
Run Code Online (Sandbox Code Playgroud)

现在是一个可用的初始化程序.它返回一个可选项NSPredicate?,您必须打开结果(或使用可选绑定).例如:

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

参考文献: