Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从添加到NSDictionary中获取错误_Objective C_Ios_Cocoa - Fatal编程技术网

Objective c 从添加到NSDictionary中获取错误

Objective c 从添加到NSDictionary中获取错误,objective-c,ios,cocoa,Objective C,Ios,Cocoa,我初始化了NSDictionary、main_dict和NSMustable数组insert。然后我将主_事件添加到插入数组中。最后,使用键值将该数组添加到字典中 当我进入[main_dict setValue:insert forKey:count]时,我得到了SIG_ABRT信号 怎么了?我已经初始化了所有元素并有了值,但仍然是SIG_ABRT 无法修改NSDictionary类型实例。替换 main_dict = [[NSDictionary alloc] init]; NSMutable

我初始化了NSDictionary、main_dict和NSMustable数组insert。然后我将主_事件添加到插入数组中。最后,使用键值将该数组添加到字典中

当我进入
[main_dict setValue:insert forKey:count]时,我得到了SIG_ABRT信号


怎么了?我已经初始化了所有元素并有了值,但仍然是SIG_ABRT

无法修改NSDictionary类型实例。替换

main_dict = [[NSDictionary alloc] init];
NSMutableArray *insert = [[NSMutableArray alloc] init];
[insert addObject:main_event];      
NSString *count = [NSString stringWithFormat:@"%i",total_count];
[main_dict setValue:insert forKey:count];


将解决此问题。

您无法修改NSDictionary类型实例。替换

main_dict = [[NSDictionary alloc] init];
NSMutableArray *insert = [[NSMutableArray alloc] init];
[insert addObject:main_event];      
NSString *count = [NSString stringWithFormat:@"%i",total_count];
[main_dict setValue:insert forKey:count];


将解决此问题。

您需要将
main\u dict
的数据类型更改为可变类型
NSDictionary
是不可变的类型,您无法编辑它。因此,将其更改为
main_dict=[[NSMutableDictionary alloc]init]

您需要将
main\u dict
的数据类型更改为可变类型
NSDictionary
是不可变的类型,您无法编辑它。因此,将其更改为
main_dict=[[NSMutableDictionary alloc]init]

您还需要将main_dict的类型从NSDictionary*更改为NSMutableDictionary*否则在尝试调用setValue时会出现编译器错误。事实上,应该已经有这样的错误或警告了。永远不要忽略编译器警告。所有代码都应该编译干净。您还需要将main_dict的类型从NSDictionary*更改为NSMutableDictionary*,否则在尝试调用setValue时会出现编译器错误。事实上,应该已经有这样的错误或警告了。永远不要忽略编译器警告。所有代码都应该编译干净。有几件事:使用特定的对象构造函数:
count=。。。;insert=[NSArray arrayWithObject:main_事件];main_dict=[NSDictionary Dictionary WithObject:insert-forKey:count];如果使用新语法(XCode 4.5+):
count=…,会更容易些。。。;main_dict=@{count:@[main_event]}
。如果您可以将
count
用作
NSNumber
而不是字符串,则更容易:
main\u dict=@{(count):@[main\u event]}count=。。。;insert=[NSArray arrayWithObject:main_事件];main_dict=[NSDictionary Dictionary WithObject:insert-forKey:count];如果使用新语法(XCode 4.5+):
count=…,会更容易些。。。;main_dict=@{count:@[main_event]}
。如果您可以将
count
用作
NSNumber
而不是字符串,则更容易:
main\u dict=@{(count):@[main\u event]}
main_dict = [[NSMutableDictionary alloc] init];