iOS Developer Library

Developer

Foundation Framework Reference Foundation Data Types Reference

Options
Deployment Target:

On This Page
Language:

Foundation Data Types Reference

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

Data Types

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

    Declaration

    Swift

    typealias NSComparator = (AnyObject!, AnyObject!) -> NSComparisonResult

    Objective-C

    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;
    • }];

    Import Statement

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Used to describe a decimal number.

    Declaration

    Objective-C

    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.

    Import Statement

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    typealias NSHashTableOptions = Int

    Objective-C

    typedef NSUInteger NSHashTableOptions

    Import Statement

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Used to describe an integer.

    Declaration

    Swift

    typealias NSInteger = Int

    Objective-C

    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.

    Import Statement

    import ObjectiveC

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    typealias NSMapTableOptions = Int

    Objective-C

    typedef NSUInteger NSMapTableOptions

    Import Statement

    import Foundation

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    typealias NSRange = _NSRange

    Objective-C

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

    Discussion

    Foundation functions that operate on ranges include the following:

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    typealias NSRangePointer = UnsafeMutablePointer<NSRange>

    Objective-C

    typedef NSRange *NSRangePointer;

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Type for the platform-specific native socket handle.

    Declaration

    Swift

    typealias NSSocketNativeHandle = Int32

    Objective-C

    typedef int NSSocketNativeHandle;

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Type representing string-encoding values.

    Declaration

    Objective-C

    typedef NSUInteger NSStringEncoding;

    Discussion

    See String Encodings for a list of values.

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • Opaque structure containing endian-independent double value.

    Declaration

    Swift

    struct NSSwappedDouble { var v: UInt64 }

    Objective-C

    typedef struct { unsigned long long v; } NSSwappedDouble;

    Discussion

    The fields of an NSSwappedDouble are private.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Opaque type containing an endian-independent float value.

    Declaration

    Swift

    struct NSSwappedFloat { var v: UInt32 }

    Objective-C

    typedef struct { unsigned int v; } NSSwappedFloat;

    Discussion

    The fields of an NSSwappedFloat are private.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Used to specify a time interval, in seconds.

    Declaration

    Swift

    typealias NSTimeInterval = Double

    Objective-C

    typedef double NSTimeInterval;

    Discussion

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

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Objective-C

    typedef volatile void NSUncaughtExceptionHandler(NSException *exception);

    Discussion

    You can set exception handlers using NSSetUncaughtExceptionHandler.

    Import Statement

  • Used to describe an unsigned integer.

    Declaration

    Objective-C

    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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • Used to identify and manage memory zones.

    Declaration

    Objective-C

    typedef struct _NSZone NSZone;

    Import Statement

    Availability

    Available in iOS 2.0 and later.