OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 NSPredicate 和数组进行 cloudKit 搜索 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:52
标题: ios - 使用 NSPredicate 和数组进行 cloudKit 搜索

当使用 NSPredicate 时,我试图搜索包含在数组中的所有对象(字符串)。下面的代码示例有效,但谓词仅收集第一个索引中的对象?? NSPredicate 用于CKQueryOperation。 每个 Record 都有一个名为 Category 的键的值。

    let array: [String] = ["Education", "Sport", "TV and Film"]

    // select all records
    //let predicate = NSPredicate(format: "Category = %@", category )



    let predicate = NSPredicate (format: "Category == %@", argumentArray: array)

    let query = CKQuery(recordType: "quizRecord", predicate: predicate)

    // get just one value only
    let operation = CKQueryOperation(query: query)

  //code works but only queries Records with the Category for "Education" 



Best Answer-推荐答案


尝试替换:

"Category == %@"

与:

"Category IN %@"

关于ios - 使用 NSPredicate 和数组进行 cloudKit 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35221420/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4