2
在我的辦公室,我們有兩個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」返回不可變的一個問題,但我在這裏什麼都試過了還是沒有解決它。