LoginSignup
3
3

More than 5 years have passed since last update.

Realmのデータ取得時にNSDateの条件を指定する方法

Last updated at Posted at 2015-11-09

結論

NSPredicateを使う。

NSPredicate *pred = [NSPredicate predicateWithFormat:@"createdAt < %@", date];
RLMResults *results = [RealmModel objectsWithPredicate:pred];

objectsWhereだとうまくいかない

NSString *query = [NSString stringWithFormat:@"createdAt < %@", date];
RLMResults *results = [RealmModel objectsWhere:query];

↑でやると↓が出て落ちる。

Terminating app due to uncaught exception 'Invalid value', reason: 'Expected object of type date for property 'createdAt' on object of type 'RealmModel', but received: 2015-11-01 00:00:00 +0000'
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3