回到Xcode 6中,在一个使用Core Data的项目中,我有以下行。它运行良好。
fetchRequest.predicate = NSCompoundPredicate(type: .AndPredicateType, subpredicates: [predicate, datePredicate])
谓词和日期谓词 昨天我更新到了Xcode 6.1,现在上面的这一行出现了错误找不到成员"AndPredicateType"。像这样指定整个值 然后我把行改为使用下面的方便方法行。 现在我收到一个新错误无法将表达式的类型"()"转换为类型"NSPredcate?"。我不明白为什么。文档中也没有显示对 有人能告诉我如何纠正吗? 谢谢。NSCompoundPredicateType.AndPredicateType
也不起作用。fetchRequest.predicate = NSCompoundPredicate.andPredicateWithSubpredicates([predicate, datePredicate])
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