NSManagedObjectContext の変更通知をリッスンし、それに応じて OutlineView を更新する NSOutlineView のサブクラスがあります。ユーザーが報告しているある時点で奇妙なクラッシュが発生しています(自分では再現できません)...クラッシュ自体は単純なNSRangeExceptionです:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSIndexSet initWithIndexesInRange:]: Range {18446744073709551614, 1} exceeds maximum index value of NSNotFound - 1'
しかし、紛らわしい部分は、これが起こっているコードです:
- (void) addedObject: (CommonListData *) item toExistingSection: (CommonListData *) existingSection atIndex: (NSInteger) index {
if (index != NSNotFound) {
[self beginUpdates];
[self insertItemsAtIndexes: [NSIndexSet indexSetWithIndex: index] inParent: existingSection withAnimation:NSTableViewAnimationEffectFade | NSTableViewAnimationSlideDown];
[self endUpdates];
NSInteger scrollPosition = [self rowForItem: item];
if (scrollPosition != NSNotFound && scrollPosition !=0) {
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:scrollPosition - 1]; // crashes here
NSNotFound と 0 をチェックしているのに、indexSetWithIndex:(scrollPosition-1)
まだ NSRangeException が発生するのはなぜですか? scollPosition が有効か無効かを確認するために他に何を確認できますか?
これが関連しているかどうかはわかりませんが、Core Data スタックが iCloud に接続されていて、NSPersistentStoreDidImportUbiquitousContentChangesNotification を取得し、コンテキストを使用して通知で mergeChangesFromContextDidSaveNotification を実行した場合にのみ発生します。