简体   繁体   English

Xcode 6.1中的NSCompoundPredicate错误

[英]NSCompoundPredicate error in Xcode 6.1

Back in Xcode 6, in a project using Core Data I had the following line. 回到Xcode 6,在使用Core Data的项目中,我有以下几行。 It worked fine. 它工作正常。

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

predicate and datePredicate are of NSPredicate type. predicatedatePredicate属于NSPredicate类型。

Yesterday I updated to Xcode 6.1 and now this above line gives this error Could not find member 'AndPredicateType' . 昨天我更新到Xcode 6.1,现在上面这行给出了这个错误找不到成员'AndPredicateType' Specifying the entire value like this NSCompoundPredicateType.AndPredicateType didn't work either. NSCompoundPredicateType.AndPredicateType这样指定整个值也不起作用。

Then I changed the line to use its convenience method line below. 然后我改变了行,使用下面的方便方法行。

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

Now I get a new error Cannot convert the expression's type '()' to type 'NSPredicate?' 现在我得到一个新错误无法将表达式的类型'()'转换为'NSPredicate?' . I don't understand why. 我不明白为什么。 The documentation doesn't show any deprecations or changes to NSCompoundPredicate either. 文档也未显示对NSCompoundPredicate任何弃用或更改。

Can anyone please tell me how to correct this? 谁能告诉我如何解决这个问题?

Thank you. 谢谢。

The initializer 初始化器

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

is a failable initializer now. 现在是一个失败的初始化程序 It returns an optional NSPredicate? 它返回一个可选的NSPredicate? and you have to unwrap the result (or use optional binding). 你必须打开结果(或使用可选的绑定)。 For example: 例如:

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

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM