Class

NSPointerArray

The NSPointerArray class represents a mutable collection modeled after NSArray, but can also hold nil values. nil values may be inserted or removed and contribute to the object’s count. An NSPointerArray object can also increase and decrease its count directly.

Overview

A pointer array can be initialized to maintain strong or weak references to objects, or according to any of the memory or personality options defined by NSPointerFunctions.Options.

The NSCopying and NSCoding protocols are applicable only when a pointer array is initialized to maintain strong or weak references to objects.

When enumerating a pointer array with NSFastEnumeration using for...in, the loop will yield any nil values present in the array. See Fast Enumeration Makes It Easy to Enumerate a Collection in Programming with Objective-C for more information.

Subclassing Notes

NSPointerArray is not suitable for subclassing.

Symbols

Creating and Initializing a New Pointer Array

init(options: NSPointerFunctions.Options = [])

Initializes the receiver to use the given options.

init(pointerFunctions: NSPointerFunctions)

Initializes the receiver to use the given functions.

class func strongObjects()

Returns a new pointer array that maintains strong references to its elements.

class func weakObjects()

Returns a new pointer array that maintains weak references to its elements.

Managing the Collection

var count: Int

The number of elements in the receiver.

var allObjects: [Any]

All the objects in the receiver.

func pointer(at: Int)

Returns the pointer at a given index.

func addPointer(UnsafeMutableRawPointer?)

Adds a given pointer to the receiver.

func removePointer(at: Int)

Removes the pointer at a given index.

func compact()

Removes NULL values from the receiver.

Getting the Pointer Functions

var pointerFunctions: NSPointerFunctions

The functions in use by the receiver.