Swift:使用NSPredicate的'IN'查询替代方案,用于从iCloud中获取记录 [英] Swift: 'IN' query alternative using NSPredicate for fetching records from iCloud

查看:135
本文介绍了Swift:使用NSPredicate的'IN'查询替代方案,用于从iCloud中获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iCloud 中,我想在Item的表中搜索,我的表中有userId列,但是我不知道如何

In iCloud, I want to search in Item's table, where I have userId column in swift but I didn't know how

表格:用户

UserId {String type}
UserName {String type}

表格:项目

ItemId {String type}
ItemName {String type}
UserId {String type}

我需要NSPredicate替代此查询

I need NSPredicate alternative to this query

Select * from item where userId in (2,3,4)

还有什么办法可以让我直接在iCloud中触发SQL查询吗?

Also, is there any way so I can fire sql query directly in iCloud?

这是在Swift中完成上述操作的正确方法吗?

Is this is the correct way of doing above in Swift?

var orList = [NSPredicate]()
orList.append(NSPredicate(format: "userId = %i", 2))
orList.append(NSPredicate(format: "userId = %i", 3))       
orList.append(NSPredicate(format: "userId = %i", 4))

或者有什么方法可以传递[2,3,4]数组

谢谢-

推荐答案

尝试一下;

let usrIds:[Int] = [1,2,3];
let predicate:NSPredicate = NSPredicate(format: "userId IN %@", usrIds);

参考 https://developer.apple.com/library /mac/documentation/Cocoa/Conceptual/Predicates/Articles/pUsing.html

这篇关于Swift:使用NSPredicate的'IN'查询替代方案,用于从iCloud中获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆