Class: NSMutableArray
Overview
The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray.
Direct Known Subclasses
Class Method Summary (collapse)
-
+ arrayWithCapacity:
Creates and returns an NSMutableArray object with enough allocated memory to initially hold a given number of objects.
Instance Method Summary (collapse)
-
- addObject:
Inserts a given object at the end of the array.
-
- addObjectsFromArray:
Adds the objects contained in another given array to the end of the receiving array’s content.
-
- exchangeObjectAtIndex:withObjectAtIndex:
Exchanges the objects in the array at given indices.
-
- filterUsingPredicate:
Evaluates a given predicate against the array’s content and leaves only objects that match.
-
- initWithCapacity:
Returns an array, initialized with enough memory to initially hold a given number of objects.
-
- insertObject:atIndex:
Inserts a given object into the array’s contents at a given index.
-
- insertObjects:atIndexes:
Inserts the objects in the provided array into the receiving array at the specified indexes.
-
- removeAllObjects
Empties the array of all its elements.
-
- removeLastObject
Removes the object with the highest-valued index in the array .
-
- removeObject:
Removes all occurrences in the array of a given object.
-
- removeObject:inRange:
Removes all occurrences within a specified range in the array of a given object.
-
- removeObjectAtIndex:
Removes the object at index .
-
- removeObjectIdenticalTo:
Removes all occurrences of a given object in the array.
-
- removeObjectIdenticalTo:inRange:
Removes all occurrences of anObject within the specified range in the array.
-
- removeObjectsAtIndexes:
Removes the objects at the specified indexes from the array.
-
- removeObjectsInArray:
Removes from the receiving array the objects in another given array.
-
- removeObjectsInRange:
Removes from the array each of the objects within a given range.
-
- replaceObjectAtIndex:withObject:
Replaces the object at index with anObject.
-
- replaceObjectsAtIndexes:withObjects:
Replaces the objects in the receiving array at specified locations specified with the objects from a given array.
-
- replaceObjectsInRange:withObjectsFromArray:
Replaces the objects in the receiving array specified by a given range with all of the objects from a given array.
-
- replaceObjectsInRange:withObjectsFromArray:range:
Replaces the objects in the receiving array specified by one given range with the objects in another array specified by another range.
-
- setArray:
Sets the receiving array’s elements to those in another given array.
-
- setObject:atIndexedSubscript:
Replaces the object at the index with the new object, possibly adding the object.
-
- sortUsingComparator:
Sorts the array using the comparison method specified by a given NSComparator Block.
-
- sortUsingDescriptors:
Sorts the receiving array using a given array of sort descriptors.
-
- sortUsingFunction:context:
Sorts the array’s elements in ascending order as defined by the comparison function compare.
-
- sortUsingSelector:
Sorts the array’s elements in ascending order, as determined by the comparison method specified by a given selector.
-
- sortWithOptions:usingComparator:
Sorts the array using the specified options and the comparison method specified by a given NSComparator Block.
Methods inherited from NSArray
#addObserver:forKeyPath:options:context:, #addObserver:toObjectsAtIndexes:forKeyPath:options:context:, array, #arrayByAddingObject:, #arrayByAddingObjectsFromArray:, arrayWithArray:, arrayWithContentsOfFile:, arrayWithContentsOfURL:, arrayWithObject:, arrayWithObjects:, arrayWithObjects:count:, #componentsJoinedByString:, #containsObject:, #count, #description, #descriptionWithLocale:, #descriptionWithLocale:indent:, #enumerateObjectsAtIndexes:options:usingBlock:, #enumerateObjectsUsingBlock:, #enumerateObjectsWithOptions:usingBlock:, #filteredArrayUsingPredicate:, #firstObjectCommonWithArray:, #getObjects:range:, #indexOfObject:, #indexOfObject:inRange:, #indexOfObject:inSortedRange:options:usingComparator:, #indexOfObjectAtIndexes:options:passingTest:, #indexOfObjectIdenticalTo:, #indexOfObjectIdenticalTo:inRange:, #indexOfObjectPassingTest:, #indexOfObjectWithOptions:passingTest:, #indexesOfObjectsAtIndexes:options:passingTest:, #indexesOfObjectsPassingTest:, #indexesOfObjectsWithOptions:passingTest:, #initWithArray:, #initWithArray:copyItems:, #initWithContentsOfFile:, #initWithContentsOfURL:, #initWithObjects:, #initWithObjects:count:, #isEqualToArray:, #lastObject, #makeObjectsPerformSelector:, #makeObjectsPerformSelector:withObject:, #objectAtIndex:, #objectAtIndexedSubscript:, #objectEnumerator, #objectsAtIndexes:, #pathsMatchingExtensions:, #removeObserver:forKeyPath:, #removeObserver:forKeyPath:context:, #removeObserver:fromObjectsAtIndexes:forKeyPath:, #removeObserver:fromObjectsAtIndexes:forKeyPath:context:, #reverseObjectEnumerator, #setValue:forKey:, #sortedArrayHint, #sortedArrayUsingComparator:, #sortedArrayUsingDescriptors:, #sortedArrayUsingFunction:context:, #sortedArrayUsingFunction:context:hint:, #sortedArrayUsingSelector:, #sortedArrayWithOptions:usingComparator:, #subarrayWithRange:, #valueForKey:, #writeToFile:atomically:, #writeToURL:atomically:
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Object) arrayWithCapacity(numItems)
Creates and returns an NSMutableArray object with enough allocated memory to initially hold a given number of objects. Mutable arrays expand as needed; numItems simply establishes the object’s initial capacity.
Instance Method Details
- (Object) addObject(anObject)
Inserts a given object at the end of the array.
- (Object) addObjectsFromArray(otherArray)
Adds the objects contained in another given array to the end of the receiving array’s content.
- (Object) exchangeObjectAtIndex(idx1, withObjectAtIndex:idx2)
Exchanges the objects in the array at given indices.
- (Object) filterUsingPredicate(predicate)
Evaluates a given predicate against the array’s content and leaves only objects that match
- (Object) initWithCapacity(numItems)
Returns an array, initialized with enough memory to initially hold a given number of objects. Mutable arrays expand as needed; numItems simply establishes the object’s initial capacity.
- (Object) insertObject(anObject, atIndex:index)
Inserts a given object into the array’s contents at a given index. If index is already occupied, the objects at index and beyond are shifted by adding 1 to their indices to make room. Note that NSArray objects are not like C arrays. That is, even though you specify a size when you create an array, the specified size is regarded as a “hint”; the actual size of the array is still 0. This means that you cannot insert an object at an index greater than the current count of an array. For example, if an array contains two objects, its size is 2, so you can add objects at indices 0, 1, or 2. Index 3 is illegal and out of bounds; if you try to add an object at index 3 (when the size of the array is 2), NSMutableArray raises an exception.
- (Object) insertObjects(objects, atIndexes:indexes)
Inserts the objects in the provided array into the receiving array at the specified indexes. Each object in objects is inserted into the receiving array in turn at the corresponding location specified in indexes after earlier insertions have been made. The implementation is conceptually similar to that illustrated in the following example. The resulting behavior is illustrated by the following example. The locations specified by indexes may therefore only exceed the bounds of the receiving array if one location specifies the count of the array or the count of the array after preceding insertions, and other locations exceeding the bounds do so in a contiguous fashion from that location, as illustrated in the following examples.In this example, both new objects are appended to the end of the array. If you replace [indexes addIndex:4] with [indexes addIndex:6] (so that the indexes are 5 and 6), then the application will fail with an out of bounds exception.In this example, two objects are added into the middle of the array, and another at the current end of the array (index 4) which means that it is third from the end of the modified array. If you replace [indexes addIndex:4] with [indexes addIndex:6] (so that the indexes are 1, 2, and 6), then the output is (one, a, b, two, three, four, c).If objects or indexes is nil this method will raise an exception.
- (Object) removeAllObjects
Empties the array of all its elements.
- (Object) removeLastObject
Removes the object with the highest-valued index in the array
removeLastObject raises an NSRangeException if there are no objects in the array.
- (Object) removeObject(anObject)
Removes all occurrences in the array of a given object. This method uses indexOfObject: to locate matches and then removes them by using removeObjectAtIndex:. Thus, matches are determined on the basis of an object’s response to the isEqual: message. If the array does not contain anObject, the method has no effect (although it does incur the overhead of searching the contents).
- (Object) removeObject(anObject, inRange:aRange)
Removes all occurrences within a specified range in the array of a given object. Matches are determined on the basis of an object’s response to the isEqual: message. If the array does not contain anObject within aRange, the method has no effect (although it does incur the overhead of searching the contents).
- (Object) removeObjectAtIndex(index)
Removes the object at index . To fill the gap, all elements beyond index are moved by subtracting 1 from their index.
- (Object) removeObjectIdenticalTo(anObject)
Removes all occurrences of a given object in the array. This method uses the indexOfObjectIdenticalTo: method to locate matches and then removes them by using removeObjectAtIndex:. Thus, matches are determined using object addresses. If the array does not contain anObject, the method has no effect (although it does incur the overhead of searching the contents).
- (Object) removeObjectIdenticalTo(anObject, inRange:aRange)
Removes all occurrences of anObject within the specified range in the array.
This method uses the indexOfObjectIdenticalTo: method to locate matches and then removes them by using removeObjectAtIndex:. Thus, matches are determined using object addresses. If the array does not contain anObject within aRange, the method has no effect (although it does incur the overhead of searching the contents).
- (Object) removeObjectsAtIndexes(indexes)
Removes the objects at the specified indexes from the array. This method is similar to removeObjectAtIndex:, but allows you to efficiently remove multiple objects with a single operation. indexes specifies the locations of objects to be removed given the state of the array when the method is invoked, as illustrated in the following example. If indexes is nil this method will raise an exception.
- (Object) removeObjectsInArray(otherArray)
Removes from the receiving array the objects in another given array. This method is similar to removeObject:, but allows you to efficiently remove large sets of objects with a single operation. If the receiving array does not contain objects in otherArray, the method has no effect (although it does incur the overhead of searching the contents).This method assumes that all elements in otherArray respond to hash and isEqual:.
- (Object) removeObjectsInRange(aRange)
Removes from the array each of the objects within a given range. The objects are removed using removeObjectAtIndex:.
- (Object) replaceObjectAtIndex(index, withObject:anObject)
Replaces the object at index with anObject.
- (Object) replaceObjectsAtIndexes(indexes, withObjects:objects)
Replaces the objects in the receiving array at specified locations specified with the objects from a given array. The indexes in indexes are used in the same order as the objects in objects. If objects or indexes is nil this method will raise an exception.
- (Object) replaceObjectsInRange(aRange, withObjectsFromArray:otherArray)
Replaces the objects in the receiving array specified by a given range with all of the objects from a given array. If otherArray has fewer objects than are specified by aRange, the extra objects in the receiving array are removed. If otherArray has more objects than are specified by aRange, the extra objects from otherArray are inserted into the receiving array.
- (Object) replaceObjectsInRange(aRange, withObjectsFromArray:otherArray, range:otherRange)
Replaces the objects in the receiving array specified by one given range with the objects in another array specified by another range. The lengths of aRange and otherRange don’t have to be equal: if aRange is longer than otherRange, the extra objects in the receiving array are removed; if otherRange is longer than aRange, the extra objects from otherArray are inserted into the receiving array.
- (Object) setArray(otherArray)
Sets the receiving array’s elements to those in another given array.
- (Object) setObject(anObject, atIndexedSubscript:index)
Replaces the object at the index with the new object, possibly adding the object. If the index is equal to count the element is added to the end of the array, growing the array.
- (Object) sortUsingComparator(cmptr)
Sorts the array using the comparison method specified by a given NSComparator Block.
- (Object) sortUsingDescriptors(sortDescriptors)
Sorts the receiving array using a given array of sort descriptors. See NSSortDescriptor for additional information.
- (Object) sortUsingFunction(compare, context:context)
Sorts the array’s elements in ascending order as defined by the comparison function compare. This approach allows the comparison to be based on some outside parameter, such as whether character sorting is case-sensitive or case-insensitive.
- (Object) sortUsingSelector(comparator)
Sorts the array’s elements in ascending order, as determined by the comparison method specified by a given selector.
- (Object) sortWithOptions(opts, usingComparator:cmptr)
Sorts the array using the specified options and the comparison method specified by a given NSComparator Block.