如何在Realm数据库中统计具有特定值的条目。

问题描述 投票:0回答:1

我有一个带有属性dateCreated的Realm对象。

class Category: Object {
  @objc dynamic var name : String = ""
  @objc dynamic var itemn : String = ""
  @objc dynamic var dateCreated : String = ""

  var parentCategory = LinkingObjects(fromType: Datee.self , property: "cetegories")

  }

我希望能够通过var dateCreated来查询所有类别,以便在我的tableView中计算它们并创建适当的行数。

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

}
ios swift realm realm-mobile-platform
1个回答
1
投票

当你说通过dateCreated查询所有类别时,我假设你的意思是所有具有非空dateCreated字符串的类别。你可以这样做,如下所示。

var datedCategoriesCount = realm.objects(Category.self).filter("dateCreated != ''").count
© www.soinside.com 2019 - 2024. All rights reserved.