gpt4 book ai didi

iphone - [__NSCFDictionary setObject :forKey:]: mutating method sent to immutable object

转载 作者:行者123 更新时间:2023-12-03 18:41:22 28 4
gpt4 key购买 nike

-(id)init{
if (self==[super init]) {
NSMutableArray *listname = [[NSMutableArray alloc]initWithObjects:@"cu",@"al",@"zn",@"au",@"ru",@"fu",@"rb",@"pb",@"wr", nil];
NSMutableArray *listVolumn = [NSMutableArray arrayWithCapacity:[listname count]];
for (int i=0; i<[listname count]; i++) {
[listVolumn addObject:[NSNumber numberWithLong:0]];
}
nsmutabledictionary = [[NSDictionary alloc] initWithObjects:listVolumn forKeys:listname];
}
return self;
}

在我的init方法中,我定义了两个NSMutableArray,并添加到NSMutableDictionary nsmutabledictionary。在我的其他方法中:

[nsmutabledictionary setObject:[NSNumber numberWithLong:100] forKey:@"cu"];

但它在上面一行崩溃: enter image description here

最佳答案

nsmutabledictionary = [[NSDictionary alloc] initWithObjects:listVolumn forKeys:listname];

应该是

nsmutabledictionary = [[NSMutableDictionary alloc] initWithObjects:listVolumn forKeys:listname];

关于iphone - [__NSCFDictionary setObject :forKey:]: mutating method sent to immutable object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7749070/

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