[英]-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x91da0f0
when i set the value in nsmutabledictionary then given error show in image below.... 当我在nsmutabledictionary中设置值时,给定的错误显示在下图中....
here my code for setvalue in 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;
this NSMutableDictionary *dir1=[artistName objectAtIndex:i];
此NSMutableDictionary *dir1=[artistName objectAtIndex:i];
returns a NSDictionary object which turns your dir1 to the same type. 返回一个NSDictionary对象,该对象将dir1转换为相同的类型。
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. 这将确保dir1始终为NSMutableDictionary。
hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.