NSInternalInconsistencyException变异方法发送到不可变对象在Xcode 6.1

问题描述:

在我的办公室,我们有两个iMac的是,在第二次6.1NSInternalInconsistencyException变异方法发送到不可变对象在Xcode 6.1

第一的Xcode 6.0.1我们在同一个应用程序工作,并在6.0.1一切做工精细在6.1这个应用程序是崩溃。

我真的很希望我能正确地解释这个问题。

这是Xcode输出:

2014-11-03 10:48:57.358 appName[3282:505629] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object' 
*** First throw call stack: 

List item 
... 

我的问题,从这里开始,当我点击发送按钮:

-(void)sendButtonClicked 
{ 
NSMutableDictionary *pack = [self createMessagePack]; 
[Conversation addMessage:pack ToConversationWithUser:theUser]; 
[inputTextView setText:@""]; 
} 

创建包:

-(NSMutableDictionary *)createMessagePack 
{ 
NSMutableDictionary *msg = [[NSMutableDictionary alloc]init]; 
[msg setObject:CurrentUser.UserName forKey:@"sender"]; 
[msg setObject:theUser.Number forKey:@"reciever"]; 
[msg setObject:[NSDate dateWithTimeIntervalSinceNow:0] forKey:@"createdAt"]; 
[msg setObject:inputTextView.text forKey:@"text"]; 

return msg; 
} 

此塔的应用程序崩溃在这一行“[addObject addObject:message];”

+(void)addMessage : (NSMutableDictionary *)message ToConversationWithUser : (appUsers *)user 
{ 
NSMutableArray *conversation = [Conversation getConversationWithUser:user]; 
if ([conversation count] == 0) 
{ 
    [user savePerson]; 
} 
[conversation addObject:message]; 

[Conversation saveConversation:conversation WithUser:user]; 
} 

对话getConversationWithUser:用户跳到这里

+(NSMutableArray *)getConversationWithUser : (appUsers *)user 
{ 
NSMutableDictionary *allConversations = [Conversation getAllConversations]; 

NSMutableArray *theConversation = [allConversations objectForKey:user.appNumber]; 

if (!theConversation) // the conversation not exist yet.. 
{ 
    theConversation = [[NSMutableArray alloc]init]; 
} 

return theConversation; 
} 

[对话getAllConversations];跳转到这里

+(NSMutableDictionary *)getAllConversations 
{ 
NSMutableDictionary *allConversations = [[NSUserDefaults standardUserDefaults] objectForKey:@"conversations"]; 
if (!allConversations) 
{ 
    allConversations = [[NSMutableDictionary alloc]init]; 
    [[NSUserDefaults standardUserDefaults] setObject:allConversations forKey:@"conversations"]; 
} 
return allConversations; 
} 

我明白,我有“NSUserDefaults的standardUserDefaults”返回不可变的一个问题,但我在这里什么都试过了还是没有解决它。

变化:

NSMutableDictionary *allConversations = [Conversation getAllConversations]; 

这样:

NSMutableDictionary *allConversations = [[NSMutableDictionary alloc]initWithDictionary:[Conversation getAllConversations]];