Contents

associatedIndex

When this property is set to a value other than Nsnotfound 9t5v2, the receiver is one half of a move, and this value is the index of the change’s counterpart of the opposite type in the diff.

Declaration

var associatedIndex: Int { get }

Discussion

Pairs of changes with opposite types that refer to each other represent the index location of their counterpart with the associatedIndex property. The following example creates a diff where the object @”Red” moves from index 8 to index 3:

NSOrderedCollectionDifference *diff = [[NSOrderedCollectionDifference alloc] initWithChanges:@[
    [NSOrderedCollectionChange changeWithObject:@"Red" type:NSCollectionChangeRemove index:8 associatedIndex:3],
    [NSOrderedCollectionChange changeWithObject:@"Red" type:NSCollectionChangeInsert index:3 associatedIndex:8]
]];

A move pair can have a different object in its removal and insertion changes, which can imply that the change represents moving and changing or replacing an element. Diffs that controller(_:didChangeContentWith:) passes to delegates of NSFetchedResultsController communicate that an object changed even when its position in the results is unaffected.

See Also

Accessing the Change