0
NSArray* nameArr = [NSArray arrayWithObjects: @"Jill Valentine", @"Peter Griffin", @"Meg Griffin", @"Jack Lolwut",
                    @"Mike Roflcoptor", @"Cindy Woods", @"Jessica Windmill", @"Alexander The Great",
                    @"Sarah Peterson", @"Scott Scottland", @"Geoff Fanta", @"Amanda Pope", @"Michael Meyers",
                    @"Richard Biggus", @"Montey Python", @"Mike Wut", @"Fake Person", @"Chair",@"subbu",@"reddy",@"suresh",@"harish",@"naresh",@"giri",@"nani",
                    nil];

for (i=0; i<=nameArr.count i++)
{
    NSMutableDictionary *dic=[NSMutableDictionary new];
    [dic setObject:@"nameArr" forKey:@"name"];
}
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
subbu
  • 31
  • 3

4 Answers4

0

You are creating NSMutableDictionary object each and every time.

You should declare that object out side of for loop.

Here is the code

NSMutableDictionary *dic=[NSMutableDictionary new];
for (i=0; i<=nameArr.count i++)
{
  NSString *nameObj = nameArr[i];
  [dic setObject:nameObj forKey:@"name"];
}

But clear the purpose as this code is not proper.

It states that you are compiling loop number of item array has, and you are adding same array to that dictionary on same key.

vivek bhoraniya
  • 1,526
  • 2
  • 17
  • 36
0

Try like this:

NSMutableDictionary *dic = @{ @"name" : nameArr}.mutableCopy;
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
0

Try this :

If you want to add array .

NSMutableDictionary *dic = @{ @"name" : nameArr}. mutableCopy;

If you want to add array objects.

   NSMutableDictionary *dic=[NSMutableDictionary new];

   for (NSString *strname in nameArr) {
        [dic setObject:strname forKey:@"name"]
    }
KKRocks
  • 8,222
  • 1
  • 18
  • 84
0

Currently you are adding nameArr as a string, in case you need to add array for a particular key try below:

NSMutableDictionary *nameDictionary = [NSMutableDictionary new];
[dic setObject:nameArr forKey:@"name"];

Hope this helps!

iYoung
  • 3,596
  • 3
  • 32
  • 59