Nel mio RealmSwift (0.92.3) sotto Xcode6.3, come potreiRealm data-query
// the Realm Object Definition
import RealmSwift
class NameEntry: Object {
dynamic var player = ""
dynamic var gameCompleted = false
dynamic var nrOfFinishedGames = 0
dynamic var date = NSDate()
}
La corrente tableView trova il numero di oggetti (vale a dire tutti gli oggetti attualmente) come segue:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let cnt = RLM_array?.objects(NameEntry).count {
return Int(cnt)
}
else {
return 0
}
}
Prima domanda: come troverei il numero di oggetti con una data dopo, diciamo, la data del 15.06.2014 ?? (vale a dire la data-query sopra una determinata data da un oggetto RealmSwift - come funziona?). O in altre parole, come sarebbe il metodo sopra trovare il numero di oggetti con il range di date necessario ??
Il riempimento di successo di tutti i Realm-oggetti in un tableView si presenta come segue:
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
}
}
Seconda domanda: Come faccio a riempire in tableView solo le RealmSwift-oggetti che hanno una data particolare (vale a dire, ad esempio riempiendo solo gli oggetti che hanno nuovamente la data sopra il 15.06.2014). O in altre parole, come sarebbe il metodo di cui sopra solo riempire la tabellaVisualizza gli oggetti con il range di date necessario ??