user4302419
user4302419

Reputation:

RLMResults to NSArray conversion in ios

How to take RLMResults data into NSArray in objective C,please give me the suggestion.

Upvotes: 13

Views: 5867

Answers (1)

TiM
TiM

Reputation: 16021

Exactly what El Captain said. There's no way to automatically convert an RLMResults object to an NSArray; you have to do it yourself.

RLMResults *results = ...;
NSMutableArray *array = [NSMutableArray array];
for (RLMObject *object in results) {
   [array addObject:object];
}

That being said, you should ask yourself if this is truly necessary. Realm provides a lot of great under-the-hood benefits with RLMResults (for example, lazy loading the data only when accessed) which is lost when you convert them to an NSArray. It's recommended you keep the RLMResults object around and work with that as much as you can, and convert to an NSArray only when you truly need to.

Upvotes: 16

Related Questions