当我在nsmutabledictionary中设置值时,然后给出错误显示在下面的图像中....
这里是我在nsmutabledictionary
中的setvalue代码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;
答案 0 :(得分:10)
这个NSMutableDictionary *dir1=[artistName objectAtIndex:i];
返回一个NSDictionary对象,它将你的dir1转换为相同的类型。
最好的方法是做这样的事情:
NSMutableDictionary *dir1=[NSMutableDictionary dictionaryWithDictionary:[artistName objectAtIndex:i]];
或
NSMutableDictionary *dir1 = [artistName[i] mutableCopy];
这将确保dir1始终为NSMutableDictionary。
希望这会有所帮助