Realm Results To Array In Kii

147 Views Asked by At

am using Realm as a local store. I am currently trying to get the objects found in a realm Query (RLMResults) and store them in an array as part of a KiiObject.

I have very little experience using NSArray or NSDictionary to create an array of JSON to store in the KiiObject. As the number of objects in the realm search will vary i thought this might work:

for (RLMObject *object in currentEventResults) {
    [array addObject:object];
}

and then add the array to my KiiObject.

 [object setObject:array forKey:@"arryofObj"];

But the array has no objects in it when saved to Kii, but i know currentEventResults has 45 objects.

1

There are 1 best solutions below

0
On BEST ANSWER

After a night of tinkering came up with this:

for (RLMObject *object in currentEvent) {

     NSDictionary *dictOBJ = 
@{@"eventID":[object objectForKeyedSubscript:@"eventID"],
@"longValue":[object objectForKeyedSubscript:@"longValue"],
@"latValue":[object objectForKeyedSubscript:@"latValue"],
@"pingTime":[object objectForKeyedSubscript:@"pingTime"]};

            [mutableArray addObject:dictOBJ];
        }

I then :

NSArray *arrayToSave = [mutableArray copy];

I then save the array to my Kii Object.

It works well. If there is a better solution please post it.