Foundation Data Types Reference

Framework
Foundation/Foundation.h
Declared in
NSAppleEventManager.h
NSByteOrder.h
NSDate.h
NSDecimal.h
NSGeometry.h
NSHashTable.h
NSMapTable.h
NSObjCRuntime.h
NSPort.h
NSRange.h
NSString.h
NSZone.h
objc/NSObjCRuntime.h

Overview

This document describes the data types and constants found in the Foundation framework.

Data Types

NSAppleEventManagerSuspensionID

Identifies an Apple event whose handling has been suspended. Can be used to resume handling of the Apple event.

typedef const struct __NSAppleEventManagerSuspension *NSAppleEventManagerSuspensionID;
Availability
  • Available in OS X v10.3 and later.
Declared In
NSAppleEventManager.h

NSComparator

Defines the signature for a block object used for comparison operations.

typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
Discussion

The arguments to the block are two objects to compare. The block returns an NSComparisonResult value to denote the ordering of the two objects.

You use NSComparator blocks in comparison operations such as NSArray’s sortedArrayUsingComparator:, for example:

NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) {
 
    if ([obj1 integerValue] > [obj2 integerValue]) {
        return (NSComparisonResult)NSOrderedDescending;
    }
 
    if ([obj1 integerValue] < [obj2 integerValue]) {
        return (NSComparisonResult)NSOrderedAscending;
    }
    return (NSComparisonResult)NSOrderedSame;
}];
Availability
  • Available in OS X v10.6 and later.
Declared In
NSObjCRuntime.h

NSDecimal

Used to describe a decimal number.

typedef struct {
      signed int _exponent:8;
      unsigned int _length:4;
      unsigned int _isNegative:1;
      unsigned int _isCompact:1;
      unsigned int _reserved:18;
      unsigned short _mantissa[NSDecimalMaxSize];
} NSDecimal;
Discussion

The fields of NSDecimal are private.

Used by the functions described in “Decimals” in Foundation Functions Reference.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSDecimal.h

NSHashEnumerator

Allows successive elements of a hash table to be returned each time this structure is passed to NSNextHashEnumeratorItem.

typedef struct {
      unsigned _pi;
      unsigned _si void *_bs;
} NSHashEnumerator;
Discussion

The fields of NSHashEnumerator are private.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHashTable.h

NSHashTable

The opaque data type used by the functions described in “Hash Tables” in Foundation Functions Reference.

typedef struct _NSHashTable NSHashTable;
Discussion

For OS X v10.5 and later, see also NSHashTable.

Availability
  • Available in OS X v10.0 through OS X v10.4.
Declared In
NSHashTable.h

NSHashTableCallBacks

Defines a structure that contains the function pointers used to configure behavior of NSHashTable with respect to elements within a hash table.

typedef struct {
      unsigned (*hash)(NSHashTable *table, const void *);
      BOOL (*isEqual)(NSHashTable *table, const void *, const void  *);
      void (*retain)(NSHashTable *table, const void *);
      void (*release)(NSHashTable *table, void *);
      NSString *(*describe)(NSHashTable *table, const void *);
} NSHashTableCallBacks;
Fields
hash

Points to the function that must produce hash code for elements of the hash table. If NULL, the pointer value is used as the hash code. Second parameter is the element for which hash code should be produced.

isEqual

Points to the function that compares second and third parameters. If NULL, then == is used for comparison.

retain

Points to the function that increments a reference count for the given element. If NULL, then nothing is done for reference counting.

release

Points to the function that decrements a reference count for the given element, and if the reference count becomes 0, frees the given element. If NULL, then nothing is done for reference counting or releasing.

describe

Points to the function that produces an autoreleased NSString * describing the given element. If NULL, then the hash table produces a generic string description.

Discussion

All functions must know the types of things in the hash table to be able to operate on them. Sets of predefined call backs are described in NSHashTable Class Reference.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHashTable.h

NSHashTableOptions

Specifies a bitfield used to configure the behavior of elements in an instance of NSHashTable.

typedef NSUInteger NSHashTableOptions
Availability
  • Available in OS X v10.5 and later.
Declared In
NSHashTable.h

NSInteger

Used to describe an integer.

typedef long NSInteger;
Discussion

When building 32-bit applications, NSInteger is a 32-bit integer. A 64-bit application treats NSInteger as a 64-bit integer.

Availability
  • Available in OS X v10.5 and later.
Declared In
objc/NSObjCRuntime.h

NSMapEnumerator

Allows successive elements of a map table to be returned each time this structure is passed to NSNextMapEnumeratorPair.

typedef struct {
      unsigned _pi;
      unsigned _si;
      void *_bs;
} NSMapEnumerator;
Discussion

The fields of NSMapEnumerator are private.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMapTable.h

NSMapTable

The opaque data type used by the functions described in “Managing Map Tables” in Foundation Functions Reference.

typedef struct _NSMapTable NSMapTable;
Discussion

For OS X v10.5 and later, see also NSMapTable.

Availability
  • Available in OS X v10.0 through OS X v10.4.
Declared In
NSMapTable.h

NSMapTableKeyCallBacks

The function pointers used to configure behavior of NSMapTable with respect to key elements within a map table.

typedef struct {
      unsigned (*hash)(NSMapTable *table, const void *);
      BOOL (*isEqual)(NSMapTable *table, const void *, const void  *);
      void (*retain)(NSMapTable *table, const void *);
      void (*release)(NSMapTable *table, void *);
      NSString *(*describe)(NSMapTable *table, const void *);
      const void *notAKeyMarker;
} NSMapTableKeyCallBacks;
Fields
hash

Points to the function which must produce hash code for key elements of the map table. If NULL, the pointer value is used as the hash code. Second parameter is the element for which hash code should be produced.

isEqual

Points to the function which compares second and third parameters. If NULL, then == is used for comparison.

retain

Points to the function which increments a reference count for the given element. If NULL, then nothing is done for reference counting.

release

Points to the function which decrements a reference count for the given element, and if the reference count becomes zero, frees the given element. If NULL, then nothing is done for reference counting or releasing.

describe

Points to the function which produces an autoreleased NSString * describing the given element. If NULL, then the map table produces a generic string description.

notAKeyMarker

No key put in map table can be this value. An exception is raised if attempt is made to use this value as a key

Discussion

All functions must know the types of things in the map table to be able to operate on them. Sets of predefined call backs are described in NSMapTable Class Reference.

Two predefined values to use for notAKeyMarker are NSNotAnIntMapKey and NSNotAPointerMapKey.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMapTable.h

NSMapTableOptions

Specifies a bitfield used to configure the behavior of elements in an instance of NSMapTable.

typedef NSUInteger NSMapTableOptions
Availability
  • Available in OS X v10.5 and later.
Declared In
NSMapTable.h

NSMapTableValueCallBacks

The function pointers used to configure behavior of NSMapTable with respect to value elements within a map table.

typedef struct {
      void (*retain)(NSMapTable *table, const void *);
      void (*release)(NSMapTable *table, void *);
      NSString *(*describe)(NSMapTable *table, const void *);
} NSMapTableValueCallBacks;
Fields
retain

Points to the function that increments a reference count for the given element. If NULL, then nothing is done for reference counting.

release

Points to the function that decrements a reference count for the given element, and if the reference count becomes zero, frees the given element. If NULL, then nothing is done for reference counting or releasing.

describe

Points to the function that produces an autoreleased NSString * describing the given element. If NULL, then the map table produces a generic string description.

Discussion

All functions must know the types of things in the map table to be able to operate on them. Sets of predefined call backs are described in NSMapTable Class Reference.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMapTable.h

NSPoint

Represents a point in a Cartesian coordinate system.

typedef struct _NSPoint {
      CGFloat x;
      CGFloat y;
} NSPoint;
Fields
x

The x coordinate.

y

The y coordinate.

Special Considerations

Prior to OS X v10.5 the coordinates were represented by float values rather than CGFloat values.

When building for 64 bit systems, or building 32 bit like 64 bit, NSPoint is typedef’d to CGPoint.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSPointArray

Type indicating a parameter is array of NSPoint structures.

typedef NSPoint *NSPointArray;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSPointPointer

Type indicating a parameter is a pointer to an NSPoint structure.

typedef NSPoint *NSPointPointer;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSRange

A structure used to describe a portion of a series—such as characters in a string or objects in an NSArray object.

typedef struct _NSRange {
      NSUInteger location;
      NSUInteger length;
} NSRange;
Fields
location

The start index (0 is the first, as in C arrays). For type compatibility with the rest of the system, LONG_MAX is the maximum value you should use for location.

length

The number of items in the range (can be 0). For type compatibility with the rest of the system, LONG_MAX is the maximum value you should use for length.

Discussion

Foundation functions that operate on ranges include the following:

Availability
  • Available in OS X v10.0 and later.
Declared In
NSRange.h

NSRangePointer

Type indicating a parameter is a pointer to an NSRange structure.

typedef NSRange *NSRangePointer;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSRange.h

NSRect

Represents a rectangle.

typedef struct _NSRect {
      NSPoint origin;
      NSSize size;
} NSRect;
Fields
origin

The origin of the rectangle (its starting x coordinate and y coordinate).

size

The width and height of the rectangle, as measured from the origin.

Special Considerations

When building for 64 bit systems, or building 32 bit like 64 bit, NSRect is typedef’d to CGRect.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSRectArray

Type indicating a parameter is array of NSRect structures.

typedef NSRect *NSRectArray;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSRectPointer

Type indicating a parameter is a pointer to an NSRect structure.

typedef NSRect *NSRectPointer;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSSize

Represents a two-dimensional size.

typedef struct _NSSize {
      CGFloat width;
      CGFloat height;
} NSSize;
Fields
width

The width.

height

The height.

Discussion

Normally, the values of width and height are non-negative. The functions that create an NSSize structure do not prevent you from setting a negative value for these attributes. If the value of width or height is negative, however, the behavior of some methods may be undefined.

Special Considerations

Prior to OS X v10.5 the width and height were represented by float values rather than CGFloat values.

When building for 64 bit systems, or building 32 bit like 64 bit, NSSize is typedef’d to CGSize.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSSizeArray

Type indicating a parameter is an array of NSSize structures.

typedef NSSize *NSSizeArray;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSSizePointer

Type indicating parameter is a pointer to an NSSize structure.

typedef NSSize *NSSizePointer;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSGeometry.h

NSSocketNativeHandle

Type for the platform-specific native socket handle.

typedef int NSSocketNativeHandle;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSPort.h

NSStringEncoding

Type representing string-encoding values.

typedef NSUInteger NSStringEncoding;
Discussion

See String Encodings for a list of values.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSString.h

NSSwappedDouble

Opaque structure containing endian-independent double value.

typedef struct {
      unsigned long long v;
} NSSwappedDouble;
Discussion

The fields of an NSSwappedDouble are private.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSByteOrder.h

NSSwappedFloat

Opaque type containing an endian-independent float value.

typedef struct {
      unsigned int v;
} NSSwappedFloat;
Discussion

The fields of an NSSwappedFloat are private.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSByteOrder.h

NSTimeInterval

Used to specify a time interval, in seconds.

typedef double NSTimeInterval;
Discussion

NSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSDate.h

NSUncaughtExceptionHandler

Used for the function handling exceptions outside of an exception-handling domain.

typedef volatile void NSUncaughtExceptionHandler(NSException *exception);
Discussion

You can set exception handlers using NSSetUncaughtExceptionHandler.

Declared In
NSException.h

NSUInteger

Used to describe an unsigned integer.

typedef unsigned long NSUInteger;
Discussion

When building 32-bit applications, NSUInteger is a 32-bit unsigned integer. A 64-bit application treats NSUInteger as a 64-bit unsigned integer

Availability
  • Available in OS X v10.5 and later.
Declared In
objc/NSObjCRuntime.h

NSZone

Used to identify and manage memory zones.

typedef struct _NSZone NSZone;
Availability
  • Available in OS X v10.0 and later.
Declared In
NSZone.h