Reputation: 27
In objective c how to convert NSMutableArray
to NSMutableDictionary
I tried with this code.but only last index object only adding in the dictionary.
I need the format like this
ADDRESS =
{
major = 604;
minor = 37940;
uuid = "xxxxxxx";
};
{
major = 604;
minor = 37940;
uuid = "xxxxxxxxx";
};
{
major = 604;
minor = 37940;
uuid = "xxxxxxxxxx";
};
I tried with this code
NSMutableDictionary * dic1 = [NSMutableDictionary dictionary];
for (int j = 0; j <[self.beaconListArray count]; j ++)
{
[dic1 setObject:[self.beaconListArray objectAtIndex:j] forKey:@"ADDRESS"];
}
Upvotes: 0
Views: 1287
Reputation: 1334
Use this.
NSMutableDictionary * dic1 = [NSMutableDictionary new];
dic1[@"ADDRESS"] = self.beaconListArray;
Upvotes: 1
Reputation: 631
You can try to this code Dictionary
NSMutableDictionary * dic1 = [NSMutableDictionary dictionary];
Add Dictionary to array with key
[dic1 setObject:self.beaconListArray forKey:@"ADDRESS"];
Print Dictionary
NSLog(@"dic1====: %@",dic1);
Upvotes: 0
Reputation: 6454
Try like this , Because you're dictionary is overiding object and you have already array of your data and you need to create dictionary using that for address key
NSMutableDictionary * dic1 = [NSMutableDictionary dictionary];
[dic1 setObject:self.beaconListArray forKey:@"ADDRESS"];
Upvotes: 2