I have an NSArray
and I need to get data from two keys and put together in a NSMutableDictionary
. One key has string
values and the other NSNumber
values. When I try to create NSCountedSet
without adding the keys I want to use to separate arrays
, it doesn't work, because the objects are not identical, basically, I need to check if objectId
is identical, don't matter if the other keys are different.
Here is the initial code:
for (PFObject *objeto in objects) {
PFObject *exercicio = objeto[@"exercicio"];
NSString *string = exercicio.objectId;
NSNumber *nota = objeto[@"nota"];
[exercicios addObject:string];
[notas addObject:nota];
So I create two NSMutableArrays
and store the values I need. When I log
the arrays after this, they are perfectly ordered, meaning the NSString
is in the same index
of the NSNumber
it belongs to in the other array
. So far, so good.
Now, when I create the NSCountedSet
with the strings, it changes the order.
NSCountedSet *countedExercicios = [[NSCountedSet alloc] initWithArray:exercicios];
.
My goal is to sum
the NSNumbers
pertaining to an specific object, therefore, when the order changes, I lose the connection between the two arrays
.
I'm not sure what I could do to solve this problem, or even if there's a different approach to achieve the result I need.
You can create NSDictionary and add it to array. You will have just one array and you won't lose the connection, you can use objectId as a key and NSNumber as a value:
When you need get all key (objectId) you can use NSPredictate.
Hope this help