Real time date request

In my RealmSwift (0.92.3) in Xcode6.3, how would I

// the Realm Object Definition import RealmSwift class NameEntry: Object { dynamic var player = "" dynamic var gameCompleted = false dynamic var nrOfFinishedGames = 0 dynamic var date = NSDate() } 

The current View table finds the number of objects (i.e. currently all objects), for example:

 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if let cnt = RLM_array?.objects(NameEntry).count { return Int(cnt) } else { return 0 } } 

First question: how do I find the number of objects that have a date record after, say, the date 06/15/2014 ?? (i.e. a date request is above a certain date from RealmSwift-Object - how does it work?). Or, in other words, how would the method described above find the number of objects with the required date range?

Successfully populating all Realm objects in a tableView is as follows:

 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 } } 

The second question: how can I fill out the table? View only RealmSwift objects that have a specific date (for example, filling only those objects that have a date above 06/15/2014). Or, in other words, how would the above method only populate the View table of objects with the required date range?

+5
source share
1 answer

You can request Realm with dates.

If you want to receive objects after the date, use more than (>), for dates earlier, use less than (<).

Using a predicate with a specific NSDate object will do what you want:

 let realm = Realm() let predicate = NSPredicate(format: "date > %@", specificNSDate) let results = realm.objects(NameEntry).filter(predicate) 

Question 1: for the number of objects, simply enter the number of calls: results.count

Question 2: results is an NameEntrys array after specificNSDate , get the object in indexPath. Example: let nameEntry = results[indexPath.row]

To create a specific NSDate, try this answer: How do I create an NSDate for a specific date?

+13
source

All Articles