myData
myData

Reputation: 215

Want to save all the valueForKey in dictionary in either 1 array or dictionary

for (NSDictionary *fbDictionary in self.latestReactionsArray) {

    LatestReaction *latestReaction = [[LatestReaction alloc]init];

    NSDictionary *subFBDictionary = [fbDictionary objectForKey:@"participant"];   

    NSString *facebookUserID = [subFBDictionary valueForKey:@"facebook_id"];

    NSNumber* reactionIDNum = [fbDictionary valueForKey:@"reaction_id"];

    int reactionID = [reactionIDNum intValue];

    NSLog(@"what is name%@ and %@ and %d",facebookUserID, self.latestReactionsArray,reactionID);
}       

I want to save all [fbDictionary valueForKey:@"reaction_id"] in an array or dictionary. How do I do this? Thanks.

Upvotes: 0

Views: 68

Answers (2)

Gavin
Gavin

Reputation: 8200

Try this:

NSArray *reactionIDs = [self.latestReactionsArray valueForKey:@"reaction_id"];

That will give you an array of reaction IDs.

Upvotes: 1

Holly
Holly

Reputation: 5290

The reflection in Objective C is not powerful enough to get a usable list of properties that you want to map. Instead, you should implement a class method that returns a list of properties you want to map to JSON and use that.

Lastly, a common "Gotcha" is trying to add nil to a dictionary. You'll need to do a conversion from nil to [NSNull null] and back for the conversion to work properly.

Upvotes: 0

Related Questions