I realized that there is no way for setValuesForKeysWithDictionary to know which object the NSMutableArray should fill. I ended up creating a custom parameter for an array property that manually bypasses the array elements (NSDictionaries) that you pass in and calls setValuesForKeysWithDictionary for each of them.
Here is the code:
There is a property called itemList of type NSMutableArray that I want to populate for it with objects of type Item. SetItemList setter traverses an array of mystery objects, converting each NSDictionary to my Item type and adding them to a new array. Any comments on how to simplify the code are welcome.
, , Item . actionscript null , - , , , , . [item isMemberOfClass [Item class]] YES, NSDictionary. , ...
- (void) setItemList:(NSMutableArray*)input{
[itemList autorelease];
itemList = [[NSMutableArray alloc] initWithCapacity:input.count];
for(int i=0;i<input.count;i++){
Item* item = [Item new];
[item setValuesForKeysWithDictionary:(NSDictionary*)[input objectAtIndex:i]];
[itemList insertObject:item atIndex:i];
}
}
- (NSMutableArray*) itemList{
return itemList;
}