Foundation Data Types Reference

Framework
Foundation/Foundation.h
Declared in
NSByteOrder.h
NSDate.h
NSDecimal.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

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 iOS 4.0 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 iOS 2.0 and later.
Declared In
NSDecimal.h

NSHashTableOptions

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

typedef NSUInteger NSHashTableOptions
Availability
  • Available in iOS 6.0 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 iOS 2.0 and later.
Declared In
objc/NSObjCRuntime.h

NSMapTableOptions

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

typedef NSUInteger NSMapTableOptions
Availability
  • Available in iOS 6.0 and later.
Declared In
NSMapTable.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 iOS 2.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 iOS 2.0 and later.
Declared In
NSRange.h

NSSocketNativeHandle

Type for the platform-specific native socket handle.

typedef int NSSocketNativeHandle;
Availability
  • Available in iOS 2.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 iOS 2.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 iOS 2.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 iOS 2.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 iOS 2.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 iOS 2.0 and later.
Declared In
objc/NSObjCRuntime.h

NSZone

Used to identify and manage memory zones.

typedef struct _NSZone NSZone;
Availability
  • Available in iOS 2.0 and later.
Declared In
NSZone.h