How do I set a auto increment key in Realm?
I have a unique msgid for each ChatData object. @interface ChatData : RLMObject @property NSInteger msgid; .... @end But each time I create a new object I have to query all objects and get the last msgid. RLMArray *all = [[ChatData allObjects] arraySortedByProperty:@"msgid" ascending:YES]; ChatData *last = [all lastObject]; ChatData *newData = [[ChataData alloc]init]; newData.msgid = last.msgid+1; Is there an efficient way to replace this implementation? Realm doesn't have auto increment behavior, so you'll need to manage that yourself. A question I'd encourage you to ask yourself about your