A signed integer value type.

SDK

- Xcode 6.0.1+

Framework

- Swift Standard Library

## Declaration

## Overview

On 32-bit platforms, `Int`

is the same size as `Int32`

, and on 64-bit platforms, `Int`

is the same size as `Int64`

.

Structure# Int

A signed integer value type.

SDK

- Xcode 6.0.1+

Framework

- Swift Standard Library

On 32-bit platforms, `Int`

is the same size as `Int32`

, and on 64-bit platforms, `Int`

is the same size as `Int64`

.

`init<T>(T)`

Creates a new instance from the given integer.

`init?<T>(exactly: T)`

Creates a new instance from the given integer, if it can be represented exactly.

`init<Other>(clamping: Other)`

Creates a new instance with the representable value that’s closest to the given integer.

`init<T>(truncating`IfNeeded : T)

Creates a new instance from the bit pattern of the given instance by truncating or sign-extending if needed to fit this type.

`init(bit`Pattern : UInt)

Creates a new instance with the same memory representation as the given value.

`init<T>(T)`

Creates an integer from the given floating-point value, rounding toward zero. Any fractional part of the value passed as `source`

is removed.

`init?<T>(exactly: T)`

Creates an integer from the given floating-point value, if it can be represented exactly.

`init(Double)`

Creates an integer from the given floating-point value, rounding toward zero.

`init(Float)`

Creates an integer from the given floating-point value, rounding toward zero.

`init(CGFloat)`

Creates an integer from the given floating-point value, rounding toward zero.

`init(Float80)`

Creates an integer from the given floating-point value, rounding toward zero.

`init?(exactly: Double)`

Creates an integer from the given floating-point value, if it can be represented exactly.

`init?(exactly: Float)`

Creates an integer from the given floating-point value, if it can be represented exactly.

`init?(exactly: Float80)`

Creates an integer from the given floating-point value, if it can be represented exactly.

`init?(exactly: NSNumber)`

Creates an integer from the given value, if it can be represented exactly.

`init(truncating: NSNumber)`

Creates an integer from the given value, rounding toward zero when necessary.

`init(NSNumber)`

Creates an integer from the given value, rounding toward zero when necessary.

`init?(String)`

Creates a new integer value from the given string.

`init?<S>(S, radix: Int)`

Creates a new integer value from the given string and radix.

`static func random(in: Range<Int>) -> Int`

Returns a random value within the specified range.

`static func random<T>(in: Range<Int>, using: inout T) -> Int`

Returns a random value within the specified range, using the given generator as a source for randomness.

`static func random(in: Closed`Range<Int>) -> Int

Returns a random value within the specified range.

`static func random<T>(in: Closed`Range<Int>, using: inout T) -> Int

Returns a random value within the specified range, using the given generator as a source for randomness.

Integer Operators

Perform arithmetic and bitwise operations or compare values.

`func negate()`

Replaces this value with its additive inverse.

`func quotient`AndRemainder (dividingBy : Int) -> (quotient: Int, remainder: Int)

Returns the quotient and remainder of this value divided by the given value.

These methods return the result of an operation, and a flag indicating whether the operation overflowed the bounds of the type.

`func adding`ReportingOverflow (Int) -> (partialValue : Int, overflow: Bool)

Returns the sum of this value and the given value, along with a Boolean value indicating whether overflow occurred in the operation.

`func subtracting`ReportingOverflow (Int) -> (partialValue : Int, overflow: Bool)

Returns the difference obtained by subtracting the given value from this value, along with a Boolean value indicating whether overflow occurred in the operation.

`func multiplied`ReportingOverflow (by: Int) -> (partialValue : Int, overflow: Bool)

Returns the product of this value and the given value, along with a Boolean value indicating whether overflow occurred in the operation.

`func divided`ReportingOverflow (by: Int) -> (partialValue : Int, overflow: Bool)

Returns the quotient obtained by dividing this value by the given value, along with a Boolean value indicating whether overflow occurred in the operation.

`func remainder`ReportingOverflow (dividingBy : Int) -> (partialValue : Int, overflow: Bool)

Returns the remainder after dividing this value by the given value, along with a Boolean value indicating whether overflow occurred during division.

These methods perform arithmetic operations without performing bounds checks. Use these methods only when you are sure the operation won't overflow.

`func unsafe`Adding (Int) -> Int

Returns the sum of this value and the given value without checking for arithmetic overflow.

`func unsafe`Subtracting (Int) -> Int

Returns the difference obtained by subtracting the given value from this value without checking for arithmetic overflow.

`func unsafe`Multiplied (by: Int) -> Int

Returns the product of this value and the given value without checking for arithmetic overflow.

`func unsafe`Divided (by: Int) -> Int

Returns the quotient obtained by dividing this value by the given value without checking for arithmetic overflow.

`func multiplied`FullWidth (by: Int) -> (high: Int, low: Int.Magnitude)

Returns a tuple containing the high and low parts of the result of multiplying this value by the given value.

`func dividing`FullWidth ((high: Int, low: Int.Magnitude)) -> ( quotient: Int, remainder: Int)

Returns a tuple containing the quotient and remainder of dividing the given value by this value.

`var magnitude: UInt`

The magnitude of this value.

`func abs<T>(T) -> T`

Returns the absolute value of the given number.

`func signum() -> Int`

Returns `-1`

if this value is negative and `1`

if it’s positive; otherwise, `0`

.

`static var min: Int`

The minimum representable integer in this type.

`static var max: Int`

The maximum representable integer in this type.

`static var is`Signed : Bool

A Boolean value indicating whether this type is a signed integer type.

`var byte`Swapped : Int

A representation of this integer with the byte order swapped.

`var little`Endian : Int

The little-endian representation of this integer.

`var big`Endian : Int

The big-endian representation of this integer.

`init(little`Endian : Int)

Creates an integer from its little-endian representation, changing the byte order if necessary.

`init(big`Endian : Int)

Creates an integer from its big-endian representation, changing the byte order if necessary.

`static var bit`Width : Int

The number of bits used for the underlying binary representation of values of this type.

`var bit`Width : Int

The number of bits in the binary representation of this value.

`var words: Int`.Words

A collection containing the words of this value’s binary representation, in order from the least significant to most significant.

`var nonzero`BitCount : Int

The number of bits equal to 1 in this value’s binary representation.

`var leading`ZeroBitCount : Int

The number of leading zeros in this value’s binary representation.

`var trailing`ZeroBitCount : Int

The number of trailing zeros in this value’s binary representation.

These initializers create an integer with the bit pattern of the memory address of a pointer or class instance.

`init(bit`Pattern : ObjectIdentifier)

Creates an integer that captures the full value of the given object identifier.

`init<U>(bit`Pattern : UnsafePointer<U>?)

Creates a new value with the bit pattern of the given pointer.

`init<U>(bit`Pattern : UnsafeMutablePointer<U>?)

Creates a new value with the bit pattern of the given pointer.

`init(bit`Pattern : UnsafeRawPointer?)

Creates a new value with the bit pattern of the given pointer.

`init(bit`Pattern : UnsafeMutableRawPointer?)

Creates a new value with the bit pattern of the given pointer.

`init(bit`Pattern : OpaquePointer?)

Creates a new value with the bit pattern of the given pointer.

`func encode(to: Encoder)`

Encodes this value into the given encoder.

`init(from: Decoder)`

Creates a new instance by decoding from the given decoder.

`var description: String`

A textual representation of this value.

`func hash(into: inout Hasher)`

Hashes the essential components of this value by feeding them into the given hasher.

`var custom`Mirror : Mirror

A mirror that reflects the `Int`

instance.

`var custom`PlaygroundQuickLook : PlaygroundQuickLook

A custom playground Quick Look for the `Int`

instance.

`init()`

Creates a new value equal to zero.

`init(integer`Literal : Int)

Creates an instance initialized to the specified integer value.

`func distance(to: Int) -> Int`

Returns the distance from this value to the given value, expressed as a stride.

`func advanced(by: Int) -> Int`

Returns a value that is offset the specified distance from this value.

`struct Int`.Words

A type that represents the words of this integer.

`typealias Int`.Magnitude

A type that can represent the absolute value of any possible value of this type.

`typealias Int`.IntegerLiteralType

A type that represents an integer literal.

`struct Double`

A double-precision, floating-point value type.

`struct String`

A Unicode string value that is a collection of characters.

`struct Array`

An ordered, random-access collection.

`struct Dictionary`

A collection whose elements are key-value pairs.

Swift Standard Library

Solve complex problems and write high-performance, readable code.