简体   繁体   中英

How to count entries in Realm Database with a specific value

I have a Realm object with property dateCreated:

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.

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. You would do this as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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