I would like to collect some data in a method. The RLMArray
will then be used as a one to many relationship e.g. menu.dishes
+ (RLMArray<Dish> *)parseDishesFromDictionary:(NSDictionary *)resultDictionary {
NSArray *menuDishes = (NSArray*)resultDictionary[@"menuDishes"];
RLMArray<Dish> *dishes;
for (NSDictionary *menuDishDictionary in menuDishes) {
Dish *dish = [self getDishGetDishfromDictionary:menuDishDictionary];
[dishes addObject:dish];
}
return dishes;
}
The problem: the dishes array is always nil.
Is this really not possible, like the answer from this question implies?
RLMArray
is a container type that's mostly just useful for storing to-many relationships on Realm objects, and you don't get any of the collection optimizations until you've assigned it to an object, which is why Realm disallows direct initialization of RLMArray
(+new
and -init
are listed as unavailable in the docs).
So your parseDishesFromDictionary
method should return an NSArray<Dish *>
that you can then add to your RLMArray
property using -addObjects
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With