Foundation Functions

This document describes the functions and function-like macros defined in the Foundation Framework.

Symbols

Byte Ordering

func NSConvertHostFloatToSwapped(Float)

Performs a type conversion.

func NSHostByteOrder()

Returns the endian format.

func NSSwapBigDoubleToHost(NSSwappedDouble)

A utility for swapping the bytes of a number.

func NSSwapBigFloatToHost(NSSwappedFloat)

A utility for swapping the bytes of a number.

func NSSwapBigIntToHost(UInt32)

A utility for swapping the bytes of a number.

func NSSwapBigLongLongToHost(UInt64)

A utility for swapping the bytes of a number.

func NSSwapBigLongToHost(UInt)

A utility for swapping the bytes of a number.

func NSSwapBigShortToHost(UInt16)

A utility for swapping the bytes of a number.

func NSSwapDouble(NSSwappedDouble)

A utility for swapping the bytes of a number.

func NSSwapFloat(NSSwappedFloat)

A utility for swapping the bytes of a number.

func NSSwapHostDoubleToBig(Double)

A utility for swapping the bytes of a number.

func NSSwapHostDoubleToLittle(Double)

A utility for swapping the bytes of a number.

func NSSwapHostFloatToBig(Float)

A utility for swapping the bytes of a number.

func NSSwapHostFloatToLittle(Float)

A utility for swapping the bytes of a number.

func NSSwapHostIntToBig(UInt32)

A utility for swapping the bytes of a number.

func NSSwapHostIntToLittle(UInt32)

A utility for swapping the bytes of a number.

func NSSwapHostLongLongToBig(UInt64)

A utility for swapping the bytes of a number.

func NSSwapHostLongLongToLittle(UInt64)

A utility for swapping the bytes of a number.

func NSSwapHostLongToBig(UInt)

A utility for swapping the bytes of a number.

func NSSwapHostLongToLittle(UInt)

A utility for swapping the bytes of a number.

func NSSwapHostShortToBig(UInt16)

A utility for swapping the bytes of a number.

func NSSwapHostShortToLittle(UInt16)

A utility for swapping the bytes of a number.

func NSSwapInt(UInt32)

A utility for swapping the bytes of a number.

func NSSwapLittleDoubleToHost(NSSwappedDouble)

A utility for swapping the bytes of a number.

func NSSwapLittleFloatToHost(NSSwappedFloat)

A utility for swapping the bytes of a number.

func NSSwapLittleIntToHost(UInt32)

A utility for swapping the bytes of a number.

func NSSwapLittleLongLongToHost(UInt64)

A utility for swapping the bytes of a number.

func NSSwapLittleLongToHost(UInt)

A utility for swapping the bytes of a number.

func NSSwapLittleShortToHost(UInt16)

A utility for swapping the bytes of a number.

func NSSwapLong(UInt)

A utility for swapping the bytes of a number.

func NSSwapLongLong(UInt64)

A utility for swapping the bytes of a number.

func NSSwapShort(UInt16)

A utility for swapping the bytes of a number.

Decimals

You can also use the class NSDecimalNumber for decimal arithmetic.

func NSDecimalCompact(UnsafeMutablePointer<Decimal>)

Compacts the decimal structure for efficiency.

func NSDecimalIsNotANumber(UnsafePointer<Decimal>)

Returns a Boolean that indicates whether a given decimal contains a valid number.

func NSDecimalNormalize(UnsafeMutablePointer<Decimal>, UnsafeMutablePointer<Decimal>, NSDecimalNumber.RoundingMode)

Normalizes the internal format of two decimal numbers to simplify later operations.

func NSDecimalString(UnsafePointer<Decimal>, Any?)

Returns a string representation of the decimal value.

Hash Tables

func NSAllHashTableObjects(NSHashTable<AnyObject>)

Returns all of the elements in the specified hash table.

func NSCompareHashTables(NSHashTable<AnyObject>, NSHashTable<AnyObject>)

Returns a Boolean value that indicates whether the elements of two hash tables are equal.

func NSCopyHashTableWithZone(NSHashTable<AnyObject>, NSZone?)

Performs a shallow copy of the specified hash table.

func NSCountHashTable(NSHashTable<AnyObject>)

Returns the number of elements in a hash table.

func NSCreateHashTable(NSHashTableCallBacks, Int)

Creates and returns a new hash table.

func NSEnumerateHashTable(NSHashTable<AnyObject>)

Creates an enumerator for the specified hash table.

func NSFreeHashTable(NSHashTable<AnyObject>)

Deletes the specified hash table.

func NSHashInsert(NSHashTable<AnyObject>, UnsafeRawPointer?)

Adds an element to the specified hash table.

func NSHashInsertIfAbsent(NSHashTable<AnyObject>, UnsafeRawPointer?)

Adds an element to the specified hash table only if the table does not already contain the element.

func NSHashRemove(NSHashTable<AnyObject>, UnsafeRawPointer?)

Removes an element from the specified hash table.

func NSNextHashEnumeratorItem(UnsafeMutablePointer<NSHashEnumerator>)

Returns the next hash-table element in the enumeration.

func NSResetHashTable(NSHashTable<AnyObject>)

Deletes the elements of the specified hash table.

func NSStringFromHashTable(NSHashTable<AnyObject>)

Returns a string describing the hash table’s contents.

HFS File Types

func NSFileTypeForHFSTypeCode(OSType)

Returns a string encoding a file type code.

func NSHFSTypeOfFile(String!)

Returns a string encoding a file type.

Managing Map Tables

func NSAllMapTableKeys(NSMapTable<AnyObject, AnyObject>)

Returns all of the keys in the specified map table.

func NSAllMapTableValues(NSMapTable<AnyObject, AnyObject>)

Returns all of the values in the specified table.

func NSCopyMapTableWithZone(NSMapTable<AnyObject, AnyObject>, NSZone?)

Performs a shallow copy of the specified map table.

func NSCountMapTable(NSMapTable<AnyObject, AnyObject>)

Returns the number of elements in a map table.

func NSEnumerateMapTable(NSMapTable<AnyObject, AnyObject>)

Creates an enumerator for the specified map table.

func NSMapGet(NSMapTable<AnyObject, AnyObject>, UnsafeRawPointer?)

Returns a map table value for the specified key.

func NSMapInsertKnownAbsent(NSMapTable<AnyObject, AnyObject>, UnsafeRawPointer?, UnsafeRawPointer?)

Inserts a key-value pair into the specified table if the pair had not been previously added.

func NSMapRemove(NSMapTable<AnyObject, AnyObject>, UnsafeRawPointer?)

Removes a key and corresponding value from the specified table.

func NSResetMapTable(NSMapTable<AnyObject, AnyObject>)

Deletes the elements of the specified map table.

func NSStringFromMapTable(NSMapTable<AnyObject, AnyObject>)

Returns a string describing the map table’s contents.

Interacting with the Objective-C Runtime

func NSClassFromString(String)

Obtains a class by name.

func NSStringFromClass(AnyClass)

Returns the name of a class as a string.

func NSSelectorFromString(String)

Returns the selector with a given name.

func NSStringFromSelector(Selector)

Returns a string representation of a given selector.

func NSStringFromProtocol(Protocol)

Returns the name of a protocol as a string.

func NSProtocolFromString(String)

Returns a the protocol with a given name.

Logging Output

func NSLogv(String, CVaListPointer)

Logs an error message to the Apple System Log facility.

Managing File Paths

func NSFullUserName()

Returns a string containing the full name of the current user.

func NSHomeDirectory()

Returns the path to either the user’s or application’s home directory, depending on the platform.

func NSHomeDirectoryForUser(String?)

Returns the path to a given user’s home directory.

func NSOpenStepRootDirectory()

Returns the root directory of the user’s system.

func NSTemporaryDirectory()

Returns the path of the temporary directory for the current user.

func NSUserName()

Returns the logon name of the current user.

Managing Points

func NSEqualPoints(NSPoint, NSPoint)

Returns a Boolean value that indicates whether two points are equal.

func NSMakePoint(CGFloat, CGFloat)

Creates a new NSPoint from the specified values.

func NSPointFromString(String)

Returns a point from a text-based representation.

func NSStringFromPoint(NSPoint)

Returns a string representation of a point.

func NSPointFromCGPoint(CGPoint)

Returns an NSPoint typecast from a CGPoint.

func NSPointToCGPoint(NSPoint)

Returns a CGPoint typecast from an NSPoint.

Managing Ranges

func NSEqualRanges(NSRange, NSRange)

Returns a Boolean value that indicates whether two given ranges are equal.

func NSIntersectionRange(NSRange, NSRange)

Returns the intersection of the specified ranges.

func NSLocationInRange(Int, NSRange)

Returns a Boolean value that indicates whether a specified position is in a given range.

func NSMakeRange(Int, Int)

Creates a new NSRange from the specified values.

func NSMaxRange(NSRange)

Returns the sum of the location and length of the range.

func NSRangeFromString(String)

Returns a range from a textual representation.

func NSStringFromRange(NSRange)

Returns a string representation of a range.

func NSUnionRange(NSRange, NSRange)

Returns the union of the specified ranges.

Managing Rectangles

func NSContainsRect(NSRect, NSRect)

Returns a Boolean value that indicates whether one rectangle completely encloses another.

func NSEqualRects(NSRect, NSRect)

Returns a Boolean value that indicates whether the two rectangles are equal.

func NSIsEmptyRect(NSRect)

Returns a Boolean value that indicates whether a given rectangle is empty.

func NSHeight(NSRect)

Returns the height of a given rectangle.

func NSInsetRect(NSRect, CGFloat, CGFloat)

Insets a rectangle by a specified amount.

func NSIntegralRect(NSRect)

Adjusts the sides of a rectangle to integer values.

func NSIntegralRectWithOptions(NSRect, AlignmentOptions)

Adjusts the sides of a rectangle to integral values using the specified options.

func NSIntersectionRect(NSRect, NSRect)

Calculates the intersection of two rectangles.

func NSIntersectsRect(NSRect, NSRect)

Returns a Boolean value that indicates whether two rectangles intersect.

func NSMakeRect(CGFloat, CGFloat, CGFloat, CGFloat)

Creates a new NSRect from the specified values.

func NSMaxX(NSRect)

Returns the largest x coordinate of a given rectangle.

func NSMaxY(NSRect)

Returns the largest y coordinate of a given rectangle.

func NSMidX(NSRect)

Returns the x coordinate of a given rectangle’s midpoint.

func NSMidY(NSRect)

Returns the y coordinate of a given rectangle’s midpoint.

func NSMinX(NSRect)

Returns the smallest x coordinate of a given rectangle.

func NSMinY(NSRect)

Returns the smallest y coordinate of a given rectangle.

func NSMouseInRect(NSPoint, NSRect, Bool)

Returns a Boolean value that indicates whether the point is in the specified rectangle.

func NSOffsetRect(NSRect, CGFloat, CGFloat)

Offsets the rectangle by the specified amount.

func NSPointInRect(NSPoint, NSRect)

Returns a Boolean value that indicates whether a given point is in a given rectangle.

func NSRectFromString(String)

Returns a rectangle from a text-based representation.

func NSStringFromRect(NSRect)

Returns a string representation of a rectangle.

func NSRectFromCGRect(CGRect)

Returns an NSRect typecast from a CGRect.

func NSRectToCGRect(NSRect)

Returns a CGRect typecast from an NSRect.

func NSUnionRect(NSRect, NSRect)

Calculates the union of two rectangles.

func NSWidth(NSRect)

Returns the width of the specified rectangle.

Managing Sizes

func NSEqualSizes(NSSize, NSSize)

Returns a Boolean that indicates whether two size values are equal.

func NSMakeSize(CGFloat, CGFloat)

Returns a new NSSize from the specified values.

func NSSizeFromString(String)

Returns an NSSize from a text-based representation.

func NSStringFromSize(NSSize)

Returns a string representation of a size.

func NSSizeFromCGSize(CGSize)

Returns an NSSize typecast from a CGSize.

func NSSizeToCGSize(NSSize)

Returns a CGSize typecast from an NSSize.

Uncaught Exception Handlers

Whether there’s an uncaught exception handler function, any uncaught exceptions cause the program to terminate, unless the exception is raised during the posting of a notification.

func NSGetUncaughtExceptionHandler()

Returns the top-level error handler.

Core Foundation ARC Integration

func CFBridgingRetain(Any?)

Casts an Objective-C pointer to a Core Foundation pointer and also transfers ownership to the caller.

Managing Memory

func NSAllocateMemoryPages(Int)

Allocates a new block of memory.

func NSDeallocateMemoryPages(UnsafeMutableRawPointer, Int)

Deallocates the specified block of memory.

func NSLogPageSize()

Returns the binary log of the page size.

func NSPageSize()

Returns the number of bytes in a page.

func NSRealMemoryAvailable()

Returns information about the user’s system.

Deprecated
func NSRoundDownToMultipleOfPageSize(Int)

Returns the specified number of bytes rounded down to a multiple of the page size.

func NSRoundUpToMultipleOfPageSize(Int)

Returns the specified number of bytes rounded up to a multiple of the page size.