ios - 使用 NSPredicate 过滤具有对象属性的查询结果

标签 ios swift realm

是否可以过滤对象属性上的Results变量?

我有一个产品列表:

var products: Results<Product>!

产品定义如下:

class Product: Object {
  dynamic var name: String = ""
  dynamic var category: Category?
}

我可以像这样过滤名称属性上的产品:

var filteredProducts = products.filter("name contains 'test'")

问题是:是否可以使用 NSPredicate 过滤类别为 [category1,category2,category3] 的产品?

let arrCategories = [category1, category2, category3]
var filteredProducts = products.filter("category in %@", arrCategories)

最佳答案

是的,Realm 支持。

关于ios - 使用 NSPredicate 过滤具有对象属性的查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34210818/

相关文章:

ios - 文本不适合 UILabel Swift

Objective-C:将图像与之前保存的另一张图像进行比较

swift - 是否可以在 Swift 中区分 Bool 和 Int?

ios - 迁移运行后立即遍历 Realm 中的所有记录 - Swift/iOS

image - react native /Realm : how to store an image in the database?

xamarin - Realm dotnet 迁移回调未被调用

iphone - 如何识别Iphone来电并显示通知?

ios - 警告 : Attempt to present UIAlertController on UISplitViewController whose view is not in the window hierarchy

arrays - 如何定义一个固定大小的可选数组 [Swift 3]

swift - for循环写保护?