<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSPointerArray",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPointerArray"
  },
  "title" : "NSPointerArray"
}
-->

# NSPointerArray

A collection similar to an array, but with a broader range of available memory semantics.

```
class NSPointerArray
```

## Overview

The pointer array class is modeled after [`NSArray`](/documentation/Foundation/NSArray), but can also hold `nil` values. You can insert or remove `nil` values which contribute to the array’s [`count`](/documentation/Foundation/NSPointerArray/count).

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`](/documentation/Foundation/NSPointerFunctions/Options).

The [`NSCopying`](/documentation/Foundation/NSCopying) and [`NSCoding`](/documentation/Foundation/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`](/documentation/Foundation/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](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html#//apple_ref/doc/uid/TP40011210-CH7-SW30) in [Programming with Objective-C](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011210) for more information.

### Subclassing Notes

`NSPointerArray` is not suitable for subclassing.

## Topics

### Creating and Initializing a New Pointer Array

[`-  initWithOptions:`](/documentation/Foundation/NSPointerArray/init(options:))

Initializes the receiver to use the given options.

[`-  initWithPointerFunctions:`](/documentation/Foundation/NSPointerArray/init(pointerFunctions:))

Initializes the receiver to use the given functions.

[`+  pointerArrayWithOptions:`](/documentation/Foundation/NSPointerArray/pointerArrayWithOptions:)

Returns a new pointer array initialized to use the given options.

[`+  pointerArrayWithPointerFunctions:`](/documentation/Foundation/NSPointerArray/pointerArrayWithPointerFunctions:)

A new pointer array initialized to use the given functions.

[`+  strongObjectsPointerArray`](/documentation/Foundation/NSPointerArray/strongObjects())

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

[`+  pointerArrayWithStrongObjects`](/documentation/Foundation/NSPointerArray/pointerArrayWithStrongObjects)

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

[`+  weakObjectsPointerArray`](/documentation/Foundation/NSPointerArray/weakObjects())

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

[`+  pointerArrayWithWeakObjects`](/documentation/Foundation/NSPointerArray/pointerArrayWithWeakObjects)

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

### Managing the Collection

[`count`](/documentation/Foundation/NSPointerArray/count)

The number of elements in the receiver.

[`allObjects`](/documentation/Foundation/NSPointerArray/allObjects)

All the objects in the receiver.

[`-  pointerAtIndex:`](/documentation/Foundation/NSPointerArray/pointer(at:))

Returns the pointer at a given index.

[`-  addPointer:`](/documentation/Foundation/NSPointerArray/addPointer(_:))

Adds a given pointer to the receiver.

[`-  removePointerAtIndex:`](/documentation/Foundation/NSPointerArray/removePointer(at:))

Removes the pointer at a given index.

[`-  insertPointer:atIndex:`](/documentation/Foundation/NSPointerArray/insertPointer(_:at:))

Inserts a pointer at a given index.

[`-  replacePointerAtIndex:withPointer:`](/documentation/Foundation/NSPointerArray/replacePointer(at:withPointer:))

Replaces the pointer at a given index.

[`-  compact`](/documentation/Foundation/NSPointerArray/compact())

Removes `NULL` values from the receiver.

### Getting the Pointer Functions

[`pointerFunctions`](/documentation/Foundation/NSPointerArray/pointerFunctions)

The functions in use by the receiver.

[`NSPointerFunctions`](/documentation/Foundation/NSPointerFunctions)

An instance of `NSPointerFunctions` defines callout functions appropriate for managing a pointer reference held somewhere else.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`NSFastEnumeration`](/documentation/Foundation/NSFastEnumeration)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)