NSPointerArray Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in iOS 6.0 and later. |
| Companion guide | |
| Declared in | NSPointerArray.h |
Overview
NSPointerArray is a mutable collection modeled after NSArray but it can also hold NULL values, which can be inserted or extracted (and which contribute to the object’s count). Moreover, unlike traditional arrays, you can set the count of the array directly. In a garbage collected environment, if you specify a zeroing weak memory configuration, if an element is collected it is replaced by a NULL value.
The copying and archiving protocols are applicable only when a pointer array is configured for object uses.
The fast enumeration protocol (that is, use a pointer array in the for...in language construct—see “Fast Enumeration” in The Objective-C Programming Language) will yield NULL values that are present in the array. It is defined for all types of pointers although the language syntax doesn’t directly support this.
Tasks
Creating and Initializing a New Pointer Array
-
– initWithOptions: -
– initWithPointerFunctions: -
+ pointerArrayWithOptions: -
+ pointerArrayWithPointerFunctions: -
+ strongObjectsPointerArray -
+ weakObjectsPointerArray
Managing the Collection
-
– count -
– setCount: -
– allObjects -
– pointerAtIndex: -
– addPointer: -
– removePointerAtIndex: -
– insertPointer:atIndex: -
– replacePointerAtIndex:withPointer: -
– compact
Getting the Pointer Functions
Class Methods
pointerArrayWithOptions:
Returns a new pointer array initialized to use the given options.
Parameters
- options
The pointer functions options for the new instance.
Return Value
A new pointer array initialized to use the given options.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
NSPointerArray.hpointerArrayWithPointerFunctions:
A new pointer array initialized to use the given functions.
Parameters
- functions
The pointer functions for the new instance.
Return Value
A new pointer array initialized to use the given pointer functions.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
NSPointerArray.hstrongObjectsPointerArray
Returns a new pointer array that maintains strong references to its elements.
Return Value
A new pointer array that maintains strong references to its elements.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hweakObjectsPointerArray
Returns a new pointer array that maintains weak references to its elements.
Return Value
A new pointer array that maintains weak references to its elements.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hInstance Methods
addPointer:
Adds a given pointer to the receiver.
Parameters
- pointer
The pointer to add. This value may be
NULL.
Discussion
pointer is added at index count.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hallObjects
Returns an array containing all the objects in the receiver.
Return Value
An array containing all the objects in the receiver.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
NSPointerArray.hcompact
Removes NULL values from the receiver.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hcount
Returns the number of elements in the receiver.
Return Value
The number of elements in the receiver.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
NSPointerArray.hinitWithOptions:
Initializes the receiver to use the given options.
Parameters
- options
The pointer functions options for the new instance.
Return Value
The receiver, initialized to use the given options.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hinitWithPointerFunctions:
Initializes the receiver to use the given functions.
Parameters
- functions
The pointer functions for the new instance.
Return Value
The receiver, initialized to use the given functions.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hinsertPointer:atIndex:
Inserts a pointer at a given index.
Parameters
- item
The pointer to add.
- index
The index of an element in the receiver. This value must be less than the
countof the receiver.
Discussion
Elements at and above index, including NULL values, slide higher.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hpointerAtIndex:
Returns the pointer at a given index.
Parameters
- index
The index of an element in the receiver. This value must be less than the
countof the receiver.
Return Value
The pointer at index.
Discussion
The returned value may be NULL.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hpointerFunctions
Returns a new NSPointerFunctions object reflecting the functions in use by the receiver.
Return Value
A new NSPointerFunctions object reflecting the functions in use by the receiver.
Discussion
The returned object is a new NSPointerFunctions object that you can modify and/or use directly to create other pointer collections.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hremovePointerAtIndex:
Removes the pointer at a given index.
Parameters
- index
The index of an element in the receiver. This value must be less than the
countof the receiver.
Discussion
Elements above index, including NULL values, slide lower.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hreplacePointerAtIndex:withPointer:
Replaces the pointer at a given index.
Parameters
- index
The index of an element in the receiver. This value must be less than the
countof the receiver.- item
The item with which to replace the element at index. This value may be
NULL.
Availability
- Available in iOS 6.0 and later.
Declared In
NSPointerArray.hsetCount:
Sets the count for the receiver.
Parameters
- count
The count for the receiver.
Discussion
If count is greater than the count of the receiver, NULL values are added; if count is less than the count of the receiver, then elements at indexes count and greater are removed from the receiver.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
NSPointerArray.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-07-23)