Title: Theory / Important / CS / Programming / Objective-C / Library / NS / Collection / Array
On every note of this deck, unless a note says otherwise:
Language: Objective-C
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc

Typ: NSArray<Type>
Meaning: A 0-indexed immutable array of Type
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Language: Objective-C

Instruction: [NSArray<Type>
  arrayWithObjects:object_1, ..., object_n, nil
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Returns: A NSArray of size n initialized with object_1, ..., object_n
Abbreviation: @[object_1, ..., object_n]
Assuming: object_i is distinct from nil

Instruction: [array
  count
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Returns: The number of elements in array
Variables: NSArray<Type> array

Instruction: [array
  containsObject:foo
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Returns: Whether array contains foo
Variables: NSArray<Type> array

Instruction: [array
  objectAtIndexSubscript:i
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Returns: The i-th element of the array
Variables: NSArray<Type> array
Abbreviation: array[i]
Extra: Usually same as objectAtIndex
Exception: NSRangeException if i is not in range of the array

Typ: NSMutableArray
Meaning: A mutable array of NSObject
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Language: Objective-C

Instruction: [array
  addObject:foo
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Effect: add foo at the end of array
Variables: NSMutableArray array

Instruction: [array
  sortUsingSelector:selector
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Effect: sort the array according to selector order
Variables: NSMutableArray array

Instruction: [Type
  arrayWithContentsOfURL:foo
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Returns: The content of file foo as type Type

Instruction: [array reverseObjectEnumerator]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Effect: An enumerator on array in reverse order
Variables: array

Instruction: [array
  enumerateObjectsUsingBlock:foo
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html
Effect: Call foo(object, index, *stop = NO) on each element of the array, halts when stop is set to YES
Variables: NSArray<Type> array

Instruction: [array
  enumerateObjectsWithOptions:NSEnumerationConcurrent
  UsingBlock:foo
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html
Effect: Same as `[array enumerateObjectsUsingBlock:foo]` but concurrently
Variables: NSArray<Type> array

Instruction: [NSArray
  arrayWithObjects:objects
  count:count
]
[[NSArray alloc]
  initWithObjectS:objects
  count:count
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A NSArray with the count first elements of objects
Variables: id objects[]
Typ: NSMutableCopying

Question: How to override NSArray
Answer: You must override count and objectAtIndex:
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc

Instruction: [NSArray array]
[[NSArray alloc]
  init]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: An empty array

Instruction: [NSArray
  arrayWithArray:array
]
[[NSArray alloc]
  initWithArray:source
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A new array with same elements as array

Instruction: [NSArray
  arrayWithObject:object]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A new array with one element, object

Instruction: [[NSArray alloc]
  initWithArray:source
  copyItems:YES
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Effect: initialize the array with content copied from array source,
Variables: NSArray* array

Instruction: [array
  firstObject
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: The first object
Variables: NSArray* array

Instruction: [array
  lastObject
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: The last object of the array
Variables: NSArray* array

Instruction: [array
  objectAtIndex:i
]
Page: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html
Returns: The i-th element of the array
Variables: NSArray<Type> array
Extra: Usually same as objectAtIndexSubscript
Exception: NSRangeException if i is not in range of the array

Instruction: [array
  objectsAtIndexes:indexSets
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: An array containing the objects in the array at the indexes specified by indexes in the ascending order of their indexes in indexes
Variables: NSArray<Type> array

Instruction: [array
  objectEnumerator
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: Returns an enumerator object that lets you access each object in the array.
Variables: NSArray<Type> array

Instruction: [array
  indexOfObject:object
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: the lowest index whose corresponding array value is equal to a given object.
Variables: NSArray<Type> array

Instruction: [array
  indexOfObject:object
  inRange:range
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: the lowest index within a specified range whose corresponding array value is equal to a given object .
Variables: NSArray<Type> array

Instruction: [array
  indexOfObjectIdenticalTo:object
  inRange:range
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: the lowest index within a specified range whose corresponding array value is identical to the given object .
Variables: NSArray<Type> array

Instruction: [array
  indexOfObjectIdenticalTo:object
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: the lowest index whose corresponding array value is identical to the given object .
Variables: NSArray<Type> array

Instruction: [array
  indexOfObjectPassingTest:predicate
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: The index of the first object in the array that passes the predicate
Variables: NSArray<Type> array
(BOOL (^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate

Instruction: [array
  fooWithOptions:opts
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: same as [array foo] but with enumeration options opt
Variables: NSArray<Type> array
NSEnumerationOptions opts
(BOOL (^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate

Instruction: [array
  fooAtIndex: indexSet
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: same as [array foo] but enumeration limited to elements of indexes

Instruction: [array
  indexesOfObjectPassingTest:predicate
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: the indexes of objects in the array that pass a test in a given block.
Variables: NSArray<Type> array
NSEnumerationOptions opts
(BOOL (^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate

Instruction: [array
  makeObjectsPerformSelector:aSelector
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Effect: Sends to each object in the array the message identified by a given selector
Extra: raises an NSInvalidArgumentException if aSelector is NULL.

Instruction: [array
  makeObjectsPerformSelector:aSelector
  withObject:argument
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Effect: Sends to each object in the array the message aSelector:argument

Instruction: [array
  enumerateObjectsUsingBlock:block
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Effect: Executes block(ObjectType obj, NSUInteger idx, Bool* stop) for each element of the array

Instruction: [array
  firstObjectCommonWithArray:otherArray
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: The first object in array that belongt to otherArray or nil otherwise

Instruction: [array
  isEqualToArray:otherArray
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: Wether array and otherArray are equal

Instruction: [array
  arrayByAddingObject:object
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A new array, with content of array, following by object

Instruction: [array
  arrayByAddingObjectsFromArray:otherArray
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A new array, with content of array, following by content of otherArray

Instruction: [array
  filteredArrayUsingPredicate:predicate
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A new array, containing elements of array satisfying predicate

Instruction: [array
  subarrayWithRange:range
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A new array, containing elements of array in range

Instruction: [array
  sortedArrayHint
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: a “hint” that speeds the sorting of the array when the hint is supplied to sortedArrayUsingFunction:context:hint:.

Instruction: [array
  sortedArrayUsingFunction:comparator
  context:context
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: Array, with same content as array, sorted according to comparator(elt1, elt2, context)

Instruction: [array
  sortedArrayUsingFunction:comparator
  context:context
  hint:hint
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: Array, with same content as array, sorted according to comparator(elt1, elt2, context). Use hint returned by sortedArrayHint (called when the array was sorted) to speed sorting it

Instruction: [array
  sortedArrayUsingDescriptors:sortDescriptors
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A copy of the receiving array sorted as specified by sortDescriptors.
Extra: Any subsequent descriptors are used to further refine sorting of objects with duplicate values. See NSSortDescriptor for additional information.

Instruction: [array
  sortedArrayUsingSelector:comparator
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A copy of the receiving array sorted as specified by comparator.

Instruction: [array
  componentsJoinedByString:separator
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A string, with array's element, separated by separator

Instruction: [array
  description
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A string that represents the contents of the array, formatted as a property list.

Instruction: [array
  descriptionWithLocale:locale
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A string that represents the contents of the array, formatted as a property list, in locale

Instruction: [array
  descriptionWithLocale:locale
  indent:level
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A string that represents the contents of the array, formatted as a property list, in locale. Adding indentation level

Instruction: [array
  pathsMatchingExtension:filterTypes
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: The elements of array, ending with .ext for ext in filterTypes
Intuition: array an array of file name. FilterTypes the extensions we want to keep

Instruction: [array
  addObserver:(NSObject *)observer
  toObjectsAtIndexes:(NSIndexSet *)indexes
  forKeyPath:(NSString *)keyPath
  options:(NSKeyValueObservingOptions)options
  context:(void *)context;
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Effect: Registers an observer to receive key value observer notifications for the specified key-path relative to the objects at the indexes.

Instruction: [array
  removeObserver:(NSObject *)observer
  fromObjectsAtIndexes:(NSIndexSet *)indexes
  forKeyPath:(NSString *)keyPath
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Effect: Removes anObserver from all key value observer notifications associated with the specified keyPath relative to the array’s objects at indexes.

Instruction: [array
  setValue:value
  forKey:key
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Effect: Invokes setValue:forKey: on each of the array's items using the specified value and key.

Instruction: [array
  valueForKey:key
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: an array containing the results of invoking valueForKey: using key on each of the array's objects.

Instruction: [array
  shuffledArray
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: a new array that lists this array’s elements in a random order

Instruction: [array
  shuffledArrayWithRandomSource:RandomSource
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: a new array that lists this array’s elements in a random order using randomSource

Instruction: [array
  differenceFromArray:other
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: The difference between array and other

Instruction: [array
  differenceFromArray:other
  withOptions:options
  usingEquivalenceTest:equivalencBlock
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: A difference between array and other according to equivalencBlock

Instruction: [[NSArray alloc]
  initWithContentsOfURL:url
  error:errorPointer
]
[NSArray
  arrayWithContentsOfURL:url
  error:error
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: An array with content of URL

Instruction: [array
  writeToURL:url
  error:errorPointer
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Effect: Write content of array to URL

Instruction: [array
  arrayByApplyingDifference:difference
]
Page: https://developer.apple.com/documentation/foundation/nsarray?language=objc
Returns: New array, similar to array plus difference

Instruction: [array
  replaceObjectsAtIndex:indexes
  withObjects:objects
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Replaces the objects in the receiving array at locations specified with the objects from a given array.
Variables: NSMutableArray array

Instruction: [array
  replaceObjectsInRange:arrayRange
  withObjectsFromArray:otherArray
  range:otherRange
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Replaces the objects in the receiving array specified by one given range with the objects in another array specified by another range.
Variables: NSMutableArray array

Instruction: [array
  replaceObjectsInRange:arrayRange
  withObjectsFromArray:otherArray
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Replaces the objects in the receiving array specified by one given range with the objects in another array
Variables: NSMutableArray array

Instruction: [array
  setArray:otherArray
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Sets the receiving array’s elements to those in another given array.
Variables: NSMutableArray array

Instruction: [array
  filterUsingPredicate:predicate
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Evaluates a given predicate against the array’s content and leaves only objects that match.
Variables: NSMutableArray array

Instruction: [array
  exchangeObjectAtIndex:idx1
  withObjectAtIndex:idx2
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Exchanges the objects in the array at given indexes.
Variables: NSMutableArray array

Instruction: [array
  sortUsingDescriptors:sortDescriptors
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: An array containing the NSSortDescriptor objects to use to sort the receiving array’s contents.
Variables: NSMutableArray array

Instruction: [array
  sortUsingComparator:comparator
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Sorts the receiver in ascending order using the comparison method specified by a given NSComparator block.
Variables: NSMutableArray array

Instruction: [array
  sortUsingFunction:compare
  context:context
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Sorts the receiver in ascending order using `function(elt1, elt2, context)`
Variables: NSMutableArray array

Instruction: [array
  sortUsingSelector:comparator
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Sorts the receiver in ascending order using selector
Variables: NSMutableArray array

Instruction: [array
  applyDifference:difference
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Effect: Apply difference to the current array
Variables: NSMutableArray array

Instruction: [array
  getObjects:objects
  range:range
]
Page: https://developer.apple.com/documentation/foundation/nsmutablearray?language=objc
Returns: Copies references to objects contained in the array that fall within the specified range to aBuffer.
Variables: NSArray array

Typ: NSComparator
Meaning: Method to sort an array
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Language: Objective-C
Implementation: NSComparisonResult(^)(id obj1, id obj2)

Typ: NSOrderedCollectionDifference
Meaning: the difference between two ordered collections.
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Language: Objective-C

Variable: collectionDifference.hasChanges
Meaning: whether this difference has changes
Language: Objective-C
Variables: NSOrderedCollectionDifference collectionDifference

Variable: collectionDifference.insertions
Meaning: A collection of insertion change objects
Language: Objective-C
Variables: NSOrderedCollectionDifference collectionDifference

Variable: collectionDifference.removals
Meaning: A collection of removal change objects
Language: Objective-C
Variables: NSOrderedCollectionDifference collectionDifference

Instruction: [collectionDifference
  inverseDifference
]
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Effect: collectionDifference, with removal and insertion exchanged
Variables: NSOrderedCollectionDifference collectionDifference

Instruction: [[NSOrderedCollectionDifference alloc]
  initWithChanges:changes
]
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Effect: An NSOrderedCollectionDifference with the changes

Instruction: [[NSOrderedCollectionDifference alloc]
  initWithInsertIndexes
  insertedObjects:
  removeIndexes:
  removedObjects
:]
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Effect: An NSOrderedCollectionDifference with the explicitly given insertion and removals

Instruction: [[NSOrderedCollectionDifference alloc]
  initWithInsertIndexes
  insertedObjects:
  removeIndexes:
  removedObjects:
  additionalChanges:
]
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Effect: An NSOrderedCollectionDifference with the explicitly given insertion and removals and additional changes

Instruction: [difference
  differenceByTransformingChangesWithBlock:block
]
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Returns: a new ordered collection difference by mapping over this difference’s members, processing the change objects with the block provided.
Variables: NSOrderedCollectionDifference difference

Typ: NSOrderedCollectionDifferenceCalculationOptions
TypMeaning: Constants that specify the options to use when creating an ordered collection difference.
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Language: Objective-C
Value: NSOrderedCollectionDifferenceCalculationInferMoves
An option that identifies insertions or removals as moves.
Value2: NSOrderedCollectionDifferenceCalculationOmitInsertedObjects
An option that indicates that the difference should omit references to the insertions.
Value3: NSOrderedCollectionDifferenceCalculationOmitRemovedObjects
An option that indicates that the difference should omit references to the removals.

Typ: NSOrderedCollectionDifferenceCalculationOptions
Meaning: represents an indexed change within an ordered collection.
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Language: Objective-C

Instruction: [[NSOrderedCollectionChange alloc]
  initWithObject:object
  type:type
  index:index
]
[NSOrderedCollectionChange
  changeWithObject:object
  type:type
  index:index
]
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Returns: an change object that represents inserting or removing an object from an ordered collection at a specific index.

Typ: NSCollectionChangeType
TypMeaning: The type of change represented in computing the difference of an ordered collection.
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Language: Objective-C
Value: NSCollectionChangeInsert
A change type that represents the insertion of an object into an ordered collection.
Value2: NSCollectionChangeRemove
A change type that represents the removal of an object from an ordered collection.

Instruction: [[NSOrderedCollectionChange alloc]
  initWithObject:object
  type:type
  index:index
  associatedIndex:associatedIndex
]
[NSOrderedCollectionChange
  changeWithObject:object
  type:type
  index:index
  associatedIndex:associatedIndex
]
Page: https://developer.apple.com/documentation/foundation/nsrange?language=objc
Returns: A change inserting/removing object at index, with its counterpart action being done at associatedIndex (e.g. in a move, this is where the elements comes from/go to)
Typ: NSCollectionChangeType

Variable: change.index
Meaning: The index location of the change
Language: Objective-C
Variables: NSOrderedCollectionChange change

Variable: change.object
Meaning: An object the change inserts or removes.
Language: Objective-C
Variables: NSOrderedCollectionChange change

Variable: change.associatedIndex
Meaning: When this property is set to a value other than NSNotFound, 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.
Language: Objective-C
Variables: NSOrderedCollectionChange change