objective c - Purge x objects from Realm -
i want purge event log removing oldest event
objects there doesn't seem straight forward way this. can fetch object sorted according how want them deleted, there no way limit - ie want first 100 in rlmresults.
rlmresults <event *> *events = [[event allobjects] sortedresultsusingproperty:@"id" ascending:yes];
if loop through , delete them index events
updated go won't work.
rlmrealm *realm = [rlmrealm defaultrealm]; [realm beginwritetransaction]; (nsinteger = 0; < numbertopurge; i++) { [realm deleteobject:events[i]]; } [realm commitwritetransaction];
i can put add them seperate array , use delete, way works seems bit clunky, there better way?
nsmutablearray *purgeevents = [[nsmutablearray alloc] initwithcapacity:numbertopurge]; (nsinteger = 0; < numbertopurge; i++) { [purgeevents addobject:events[i]]; } rlmrealm *realm = [rlmrealm defaultrealm]; [realm beginwritetransaction]; [realm deleteobjects:events]; [realm commitwritetransaction];
no. @ present, method used of method of copying objects wish delete nsarray
, passing parent rlmrealm
object recommended way delete subset of objects @ moment. it's mentioned here in realm docs.
if you've got ideas on how think handled better, please feel free submit issue on the realm cocoa github!
Comments
Post a Comment