ios - 发送到不可变对象(immutable对象)的变异方法'
<p><p>我正在尝试将对象从字典添加到数组中。在其他部分我收到此错误</p>
<blockquote>
<p>mutating method sent to immutable object'</p>
</blockquote>
<pre><code>NSMutableDictionary *selectedDict = ;
;
;
NSMutableArray *tagListDictionary = ;
;
LineItemsStorage *linestorage = ;
if(!)
{
;
}
else{ [addObject:];
}
</code></pre>
<blockquote>
<p>-[<strong>NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'
*** First throw call stack:
(
0 CoreFoundation 0x00000001154a1d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000114f15deb objc_exception_throw + 48
2 CoreFoundation 0x00000001154a1cbd + + 205
3 CoreFoundation 0x0000000115497b0a - + 106
4 FlatPebble 0x000000010f276014 - + 836
5 UIKit 0x0000000113809a8d - + 92
6 UIKit 0x000000011397ce67 - + 67
7 UIKit 0x000000011397d143 - + 327
8 UIKit 0x000000011397c263 - + 601
9 UIKit 0x000000011387c99f - + 835
10UIKit 0x000000011387d6d4 - + 865
11UIKit 0x0000000113828dc6 - + 263
12UIKit 0x0000000113802553 _UIApplicationHandleEventQueue + 6660
13CoreFoundation 0x00000001153c7301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION</strong> + 17
14CoreFoundation 0x00000001153bd22c __CFRunLoopDoSources0 + 556
15CoreFoundation 0x00000001153bc6e3 __CFRunLoopRun + 867
16CoreFoundation 0x00000001153bc0f8 CFRunLoopRunSpecific + 488
17GraphicsServices 0x0000000116e5cad2 GSEventRunModal + 161
18UIKit 0x0000000113807f09 UIApplicationMain + 171
19*********** 0x000000010f348c2f main + 111
20libdyld.dylib 0x0000000115d9992d start + 1
)</p>
</blockquote></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用此代码</p>
<pre><code> NSMutableDictionary *selectedDict = [mutableCopy];
;
;
NSMutableArray *tagListDictionary = [mutableCopy];
;
LineItemsStorage *linestorage = ;
if(!)
{
;
}
else{ [addObject:];
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 发送到不可变对象(immutable对象)的变异方法',我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38369957/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38369957/
</a>
</p>
页:
[1]