gpt4 book ai didi

ios - -[__ NSDictionaryI setObject:forKey:]:无法识别的选择器已发送到实例0x91da0f0

转载 作者:行者123 更新时间:2023-12-01 17:20:51 25 4
gpt4 key购买 nike

当我在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;

最佳答案

NSMutableDictionary *dir1=[artistName objectAtIndex:i];返回一个NSDictionary对象,该对象将dir1转换为相同的类型。

最好的方法是做这样的事情:

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

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

这将确保dir1始终为NSMutableDictionary。

希望这可以帮助

关于ios - -[__ NSDictionaryI setObject:forKey:]:无法识别的选择器已发送到实例0x91da0f0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17057891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com