Search code examples
iosobjective-cnsarray

Adding entire array to nsdictionary


NSDictionary *searchResponseJSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

arrayOfRestaurants = searchResponseJSON[@"businesses"];

NSDictionary *businesses = [arrayOfRestaurants firstObject];

NSString *businessesID = businesses[@"id"];

I'm trying to get all the data from the array into the nsdictionary instead of just the first object. Is there a better way to do this? I cant seem to be able to get all the data from the array into the nsdictionary

Side note: I'm very new to Objective c


Solution

  • NSDictionary *dictProducts=[response valueForKey:kViewModel];
    

    Add object to Array

     [_yourArray addObject:[dictProducts objectForKey:kProductID]];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        [dict setObject: _yourArray forKey:@"Your_Key"];
    

    You can use this dictionary in this class using same key