Reputation: 123
I am querying over a RLMArray with objectsWhere and i get a RLMResults, but i need a RLMArray with the results a this point in my code.
private var data: RLMArray?
self.data = self.currentSubcategory!.datasheets // is a RLMArray
self.data = self.data!.objectsWhere("is_favourite = 1")
Upvotes: 12
Views: 9369
Reputation: 21005
You need to add objects from RLMResult
to RLMArray
...
@implementation RLMResults (RLMArrayConversion)
- (RLMArray *)toArray {
RLMArray * array = [[RLMArray alloc] initWithObjectClassName:self.objectClassName];
[array addObjects:self];
return array;
}
@end
Upvotes: 6
Reputation: 1132
RLMArray
has been split into two classes:RLMArray
andRLMResults
.RLMArray
is now used only for to-many properties onRLMObject
classes, whileRLMResults
is used for all of the querying and sorting methods. This was done to reflect that the two actually had fairly different APIs (for example,RLMResults
does not haveaddObject:
), and they’re expected to diverge further as we add change notifications for queries.The migration for this should be as simple as replacing
RLMArray
withRLMResults
in all of the places that the compiler complains about.To go with this,
arraySortedByProperty:ascending:
has been renamed tosortedResultsUsingProperty:ascending:
, andaddObjectsFromArray:
has been renamed toaddObjects:
to reflect the fact that you can pass any enumerable object to it (such asNSArray
,RLMArray
, orRLMResults
).
Source: http://realm.io/news/realm-cocoa-0.87.0/#rlmresults
Hope that's enough
Upvotes: 12
Reputation: 8138
let datasheets = self.currentSubcategory!.datasheets!.objectsWhere("is_favourite = 1")
let objects = Array(datasheets.generate())
self.data!.removeAllObjects()
self.data!.addObjects(objects)
Creating the array of the results is required because the self.data!.removeAllObjects()
line will also clear datasheets
, since RLMResults
are live-updating as you make changes to the source.
Upvotes: 4