There's no default cache expiration mechanism in Realm itself, but like you said, it's a relatively trivial matter of adding an NSDate
property to each object, and simply performing a query to check for objects whose date property is older than 24 hours periodically inside your app.
The logic could potentially look something like this in both languages:
Objective-C
NSDate *yesterday = [[NSDate alloc] initWithTimeIntervalSinceNow:-(24 * 60 *60)];
RLMResults *itemsToDelete = [ItemObject objectsWhere:"addedDate < %@", yesterday];
[[RLMRealm defaultRealm] deleteObjects:itemsToDelete];
Swift
let yesterday = NSDate(timeIntervalSinceNow:-(24*60*60))
let itemsToDelete = Realm().objects(ItemObject).filter("addedDate < (yesterday)")
Realm().delete(itemsToDelete)
I hope that helped!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…