1

when i set the value in nsmutabledictionary then given error show in image below....

enter image description here

here my code for setvalue in nsmutabledictionary

NSMutableArray *countArray=[[NSMutableArray alloc] init];
for (int i=0;i<artistName.count;i++)
{
    int count=0;
    NSMutableDictionary *dir1=[artistName objectAtIndex:i];
    NSString *artist1=[dir1 objectForKey:@"SONG_ARTIST"];

    for (int j=0;j<CurrentPlayingSong.count;j++)
    {
        NSDictionary *dir2=[CurrentPlayingSong objectAtIndex:j];
        NSString *artist2=[dir2 objectForKey:@"SONG_ARTIST"];

        if ([artist2 isEqualToString:artist1])
        {
            count++;
        }
    }

    NSString *Size=[[NSString alloc] initWithFormat:@"%d",count];
    [dir1 setObject:Size forKey:@"SIZE"];

    [countArray addObject:dir1];
}
return countArray;
nitin kachhadiya
  • 959
  • 2
  • 9
  • 21
  • The error message is quite obvious, you'd have saved a few minutes if you googled it. Voting for close, there's no need for more dupes of this. –  Jun 12 '13 at 04:55
  • possible duplicate of [NSDictionaryI setObject:forKey:\]: unrecognized selector sent to instance](http://stackoverflow.com/questions/14731353/nsdictionaryi-setobjectforkey-unrecognized-selector-sent-to-instance) –  Jun 12 '13 at 04:57
  • pls change NSString as NSMutableString, then try – manujmv Jun 12 '13 at 05:01

1 Answers1

10

this NSMutableDictionary *dir1=[artistName objectAtIndex:i]; returns a NSDictionary object which turns your dir1 to the same type.

best way is to do something like this:

NSMutableDictionary *dir1=[NSMutableDictionary dictionaryWithDictionary:[artistName objectAtIndex:i]];

or

NSMutableDictionary *dir1 = [artistName[i] mutableCopy];

This will ensure that dir1 will always be NSMutableDictionary.

hope this helps

Anupdas
  • 10,211
  • 2
  • 35
  • 60
Joshua
  • 2,432
  • 1
  • 20
  • 29