领域谓词搜索无效

时间:2015-09-14 03:33:07

标签: swift realm

在swift应用程序中使用Realm DB。我正在尝试使用谓词过滤结果,如下所示:

  class func fetchUsersFromDB(usersId: [String]) -> [User]{
        var users = [User]()
        let realm = Realm()
        let predicate = NSPredicate(format: "objectId IN %@", argumentArray: usersId)
        var allUsers = realm.objects(User).filter(predicate)
        users = Array(allUsers)
        return users
    }

但这不会编译。我收到这个错误:

Terminating app due to uncaught exception 'Invalid value', reason: 'IN clause requires an array of items'

任何想法我做错了什么?

2 个答案:

答案 0 :(得分:7)

删除argumentArray:标签,因为你正在为NSPredicate调用错误的初始化程序:

let predicate = NSPredicate(format: "objectId IN %@", usersId)

答案 1 :(得分:0)

从Swift 3开始,只需使用<form name='form1' method="post" action="nextpage.php"> <input type="text" name="t1" value="firstname"> <input type="text" name="t2" value="secondname"> <input type="submit" name="submit1"> </form> nextpage.php <?php echo $_POST['t1']; echo $_POST['t2']; ?> 代替Array(usersId)