2017-06-20 3 views
0

コレクション<__NSArrayM>を列挙しながら突然変異させた。

Application Specific Information: 
 
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x17204b070> was mutated while being enumerated.' 
 
Last Exception Backtrace: 
 
0 CoreFoundation      0x0000000186acefe0 __exceptionPreprocess + 124 
 
1 libobjc.A.dylib      0x0000000185530538 objc_exception_throw + 56 
 
2 CoreFoundation      0x0000000186acea30 __NSFastEnumerationMutationHandler + 128 
 
3 UIKit        0x000000018cc22f04 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) clearGestureRecognizers:] + 220 
 
4 UIKit        0x000000018cc22d78 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setGestureRecognizers] + 88 
 
5 UIKit        0x000000018d1d1d38 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64 
 
6 UIKit        0x000000018d1d556c _UIGestureRecognizerSendTargetActions + 124 
 
7 UIKit        0x000000018cd8f470 _UIGestureRecognizerSendActions + 252 
 
8 UIKit        0x000000018cc31380 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 720 
 
9 UIKit        0x000000018d1c5810 _UIGestureEnvironmentUpdate + 988 
 
10 UIKit        0x000000018d1c53e0 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 404 
 
11 UIKit        0x000000018d1c468c -[UIGestureEnvironment _updateGesturesForEvent:window:] + 268 
 
12 UIKit        0x000000018cc2f70c -[UIWindow sendEvent:] + 3164 
 
13 UIKit        0x000000018cc0033c -[UIApplication sendEvent:] + 340 
 
14 UIKit        0x000000018d3fa014 __dispatchPreprocessedEventFromEventQueue + 2400 
 
15 UIKit        0x000000018d3f4770 __handleEventQueue + 4268 
 
16 UIKit        0x000000018d3f4b9c __handleHIDEventFetcherDrain + 148 
 
17 CoreFoundation      0x0000000186a7d42c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 
 
18 CoreFoundation      0x0000000186a7cd9c __CFRunLoopDoSources0 + 540 
 
19 CoreFoundation      0x0000000186a7a9a8 __CFRunLoopRun + 744 
 
20 CoreFoundation      0x00000001869aada4 CFRunLoopRunSpecific + 424 
 
21 GraphicsServices     0x0000000188414074 GSEventRunModal + 100 
 
22 UIKit        0x000000018cc65058 UIApplicationMain + 208 
 
23 MyApp       0x000000010001d0ac main (main.m:16) 
 
24 libdyld.dylib      0x00000001859b959c start + 4

+1

言語タグを追加してみてください。これを引き起こすコード – doctorlove

答えて

1

このエラーの理由が考え、次のとおりです。あなたが(内部)For Each Loopを使用して配列から要素を更新または削除しようとすることができる

第一の理由
を。

For Each Loop内の要素を更新または削除しないでください。

ループのための通常の使用、あなたの配列、などでデータ操作の動作をwan't場合:あなたは(更新または削除)を変更しようとしている

int i 
for (i=0; i < array.count; i++) { 
    // update or remove operation 
} 

第二の理由
非の要素可変配列 Objective-Cプログラミング言語を使用しているというエラーメッセージが表示されます。 objective-Cでは、2種類のコレクションがあります:変更可能および変更不可。
- にNSArrayは
、収集一方の非可変型である - NSMutableArrayのだから、データ操作実行(更新、または要素を削除)するNSMutableArrayのを使用コレクション

の変更可能なタイプです。

関連する問題