简体   繁体   English

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

[英]How to count entries in Realm Database with a specific value

I have a Realm object with property dateCreated:我有一个带有属性 dateCreated 的 Realm object:

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")

  }

I want to be able to query all categories by var dateCreated in order to count them and create appropriate number or rows in my tableView.我希望能够通过 var dateCreated 查询所有类别,以便计算它们并在我的 tableView 中创建适当的数字或行。

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

}

When you say query all categories by dateCreated, I'm assuming you mean all categories with a non empty dateCreated string.当您说按 dateCreated 查询所有类别时,我假设您的意思是具有非空 dateCreated 字符串的所有类别。 You would do this as follows:你可以这样做:

var datedCategoriesCount = realm.objects(Category.self).filter("dateCreated != ''").count

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM