Reputation: 969
when i set the value in nsmutabledictionary then given error show in image below....
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;
Upvotes: 1
Views: 9693
Reputation: 2451
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
Upvotes: 10