在我的 RealmSwift (0.92.3) Xcode6.3 下,我会如何
// the Realm Object Definition
import RealmSwift
class NameEntry: Object {
dynamic var player = ""
dynamic var gameCompleted = false
dynamic var nrOfFinishedGames = 0
dynamic var date = NSDate()
}
当前的 tableView 查找对象的数量(即当前所有对象),如下所示:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let cnt = RLM_array?.objects(NameEntry).count {
return Int(cnt)
}
else {
return 0
}
}
第一个问题:我如何找到在 2014 年 6 月 15 日之后有日期条目的对象数量? (即来自 RealmSwift 对象的特定日期之上的日期查询 - 这是如何工作的?)。或者换句话说,上述方法如何找到具有所需日期范围的对象数量?
将所有 Realm-Object 成功填充到 tableView 中的情况如下所示:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("NameCell") as! PlayersCustomTableViewCell
if let arry = RLM_array {
let entry = arry.objects(NameEntry)[indexPath.row] as NameEntry
cell.playerLabel.text = entry.player
cell.accessoryType = entry.gameCompleted ? .None : .None
return cell
}
else {
cell.textLabel!.text = ""
cell.accessoryType = .None
return cell
}
}
第二个问题:我如何仅填充具有特定日期的 RealmSwift 对象(即,仅填充日期再次高于 2014 年 6 月 15 日的对象)。或者换句话说,上述方法如何仅将具有所需日期范围的对象填充到 tableView 中?