Mac Developer Library

Developer

Foundation Framework Reference NSPointerArray Class Reference

Options
Deployment Target:

On This Page
Language:

NSPointerArray

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.5 and later.

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 Makes It Easy to Enumerate a Collection in Programming with Objective-C) 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.

Subclassing Notes

NSPointerArray is not suitable for subclassing.

  • count count Property

    The number of elements in the receiver.

    Declaration

    Swift

    var count: Int

    Objective-C

    @property NSUInteger count

    Discussion

    If you increase the count, NULL values are added. If you decrease the count, elements at indexes count and greater are removed.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

  • All the objects in the receiver. (read-only)

    Declaration

    Swift

    var allObjects: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *allObjects

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

    See Also

    – count

  • Returns the pointer at a given index.

    Declaration

    Swift

    func pointerAtIndex(_ index: Int) -> UnsafeMutablePointer<Void>

    Objective-C

    - (void *)pointerAtIndex:(NSUInteger)index

    Parameters

    index

    The index of an element in the receiver. This value must be less than the count of the receiver.

    Return Value

    The pointer at index.

    Discussion

    The returned value may be NULL.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

  • Adds a given pointer to the receiver.

    Declaration

    Swift

    func addPointer(_ pointer: UnsafeMutablePointer<Void>)

    Objective-C

    - (void)addPointer:(void *)pointer

    Parameters

    pointer

    The pointer to add. This value may be NULL.

    Discussion

    pointer is added at index count.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

  • Removes the pointer at a given index.

    Declaration

    Swift

    func removePointerAtIndex(_ index: Int)

    Objective-C

    - (void)removePointerAtIndex:(NSUInteger)index

    Parameters

    index

    The index of an element in the receiver. This value must be less than the count of the receiver.

    Discussion

    Elements above index, including NULL values, slide lower.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

  • Inserts a pointer at a given index.

    Declaration

    Swift

    func insertPointer(_ item: UnsafeMutablePointer<Void>, atIndex index: Int)

    Objective-C

    - (void)insertPointer:(void *)item atIndex:(NSUInteger)index

    Parameters

    item

    The pointer to add.

    index

    The index of an element in the receiver. This value must be less than the count of the receiver.

    Discussion

    Elements at and above index, including NULL values, slide higher.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

  • Replaces the pointer at a given index.

    Declaration

    Swift

    func replacePointerAtIndex(_ index: Int, withPointer item: UnsafeMutablePointer<Void>)

    Objective-C

    - (void)replacePointerAtIndex:(NSUInteger)index withPointer:(void *)item

    Parameters

    index

    The index of an element in the receiver. This value must be less than the count of the receiver.

    item

    The item with which to replace the element at index. This value may be NULL.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

  • Removes NULL values from the receiver.

    Declaration

    Swift

    func compact()

    Objective-C

    - (void)compact

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

  • The functions in use by the receiver. (read-only)

    Declaration

    Swift

    @NSCopying var pointerFunctions: NSPointerFunctions { get }

    Objective-C

    @property(readonly, copy) NSPointerFunctions *pointerFunctions

    Discussion

    The returned object is a new NSPointerFunctions object that you can modify and/or use directly to create other pointer collections.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.