Int

struct Int

A signed integer value type.

On 32-bit platforms, Int is the same size as Int32, and on 64-bit platforms, Int is the same size as Int64.

Inheritance BitwiseOperations, CVarArg, Comparable, CustomPlaygroundQuickLookable, CustomReflectable, CustomStringConvertible, Equatable, ExpressibleByIntegerLiteral, Hashable, Integer, IntegerArithmetic, MirrorPath, SignedInteger, SignedNumber, Strideable, _Incrementable, _Integer, _IntegerArithmetic, _SignedInteger View Protocol Hierarchy →
Import import Swift

Initializers

init()

Create an instance initialized to zero.

Declaration

init()
init(_: Double)

Creates a new instance by rounding the given floating-point value toward zero.

other: A floating-point value. When other is rounded toward zero, the result must be within the range Int.min...Int.max.

Declaration

init(_ other: Double)
init(_: Float)

Creates a new instance by rounding the given floating-point value toward zero.

other: A floating-point value. When other is rounded toward zero, the result must be within the range Int.min...Int.max.

Declaration

init(_ other: Float)
init(_: Float80)

Creates a new instance by rounding the given floating-point value toward zero.

other: A floating-point value. When other is rounded toward zero, the result must be within the range Int.min...Int.max.

Declaration

init(_ other: Float80)
init(_: Int)

Declaration

init(_ value: Int)
init(_: Int8)

Declaration

init(_ value: Int8)
init(_: Int16)

Declaration

init(_ value: Int16)
init(_: Int32)

Declaration

init(_ value: Int32)
init(_: Int64)

Convert from Swift's widest signed integer type, trapping on overflow.

Declaration

init(_ value: Int64)
init(_: NSNumber)

[Foundation]

Declaration

init(_ number: NSNumber)
init(_: UInt)

Declaration

init(_ value: UInt)
init(_: UInt8)

Declaration

init(_ value: UInt8)
init(_: UInt16)

Declaration

init(_ value: UInt16)
init(_: UInt32)

Declaration

init(_ value: UInt32)
init(_: UInt64)

Declaration

init(_ value: UInt64)
init(bigEndian:)

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

Declaration

init(bigEndian value: Int)
init(bitPattern: ObjectIdentifier)

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

Declaration

init(bitPattern objectID: ObjectIdentifier)
init(bitPattern: OpaquePointer?)

Declaration

init(bitPattern pointer: OpaquePointer?)
init(bitPattern: UInt)

Construct a Int having the same memory representation as the UInt bitPattern. No range or overflow checking occurs, and the resulting Int may not have the same numeric value as bitPattern--it is only guaranteed to use the same pattern of bits.

Declaration

init(bitPattern: UInt)
init(bitPattern: UnsafeMutableRawPointer?)

Declaration

init(bitPattern: UnsafeMutableRawPointer?)
init(bitPattern: UnsafeRawPointer?)

Declaration

init(bitPattern: UnsafeRawPointer?)
init<U>(bitPattern: UnsafeMutablePointer<U>?)

Declaration

init<U>(bitPattern: UnsafeMutablePointer<U>?)
init<U>(bitPattern: UnsafePointer<U>?)

Declaration

init<U>(bitPattern: UnsafePointer<U>?)
init(integerLiteral:)

Create an instance initialized to value.

Declaration

init(integerLiteral value: Int)
init(littleEndian:)

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

Declaration

init(littleEndian value: Int)
init(truncatingBitPattern: Int64)

Construct a Int having the same bitwise representation as the least significant bits of the provided bit pattern.

No range or overflow checking occurs.

Declaration

init(truncatingBitPattern: Int64)
init(truncatingBitPattern: UInt64)

Construct a Int having the same bitwise representation as the least significant bits of the provided bit pattern.

No range or overflow checking occurs.

Declaration

init(truncatingBitPattern: UInt64)
init?(_:radix:)

Construct from an ASCII representation in the given radix.

If text does not match the regular expression "[+-]?[0-9a-zA-Z]+", or the value it denotes in the given radix is not representable, the result is nil.

Declaration

init?(_ text: String, radix: Int = default)
init?(exactly: Int)

Declaration

init?(exactly value: Int)
init?(exactly: Int8)

Declaration

init?(exactly value: Int8)
init?(exactly: Int16)

Declaration

init?(exactly value: Int16)
init?(exactly: Int32)

Declaration

init?(exactly value: Int32)
init?(exactly: Int64)

Declaration

init?(exactly value: Int64)
init?(exactly: UInt)

Declaration

init?(exactly value: UInt)
init?(exactly: UInt8)

Declaration

init?(exactly value: UInt8)
init?(exactly: UInt16)

Declaration

init?(exactly value: UInt16)
init?(exactly: UInt32)

Declaration

init?(exactly value: UInt32)
init?(exactly: UInt64)

Declaration

init?(exactly value: UInt64)

Static Variables

static var allZeros: Int

The empty bitset of type Int.

Declaration

static var allZeros: Int { get }
static var max: Int

Declaration

static var max: Int { get }
static var min: Int

Declaration

static var min: Int { get }

Instance Variables

var bigEndian: Int

Returns the big-endian representation of the integer, changing the byte order if necessary.

Declaration

var bigEndian: Int { get }
var byteSwapped: Int

Returns the current integer with the byte order swapped.

Declaration

var byteSwapped: Int { get }
var customMirror: Mirror

A mirror that reflects the Int instance.

Declaration

var customMirror: Mirror { get }
var customPlaygroundQuickLook: PlaygroundQuickLook

A custom playground Quick Look for this instance.

If this type has value semantics, the PlaygroundQuickLook instance should be unaffected by subsequent mutations.

Declaration

var customPlaygroundQuickLook: PlaygroundQuickLook { get }
var description: String

A textual representation of self.

Declaration

var description: String { get }
var hashValue: Int

The hash value.

Axiom: x == y implies x.hashValue == y.hashValue.

Note: The hash value is not guaranteed to be stable across different invocations of the same program. Do not persist the hash value across program runs.

Declaration

var hashValue: Int { get }
var littleEndian: Int

Returns the little-endian representation of the integer, changing the byte order if necessary.

Declaration

var littleEndian: Int { get }

Static Methods

static func addWithOverflow(_:_:)

Add lhs and rhs, returning a result and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func addWithOverflow(_ lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
static func divideWithOverflow(_:_:)

Divide lhs and rhs, returning a result and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func divideWithOverflow(_ lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
static func multiplyWithOverflow(_:_:)

Multiply lhs and rhs, returning a result and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func multiplyWithOverflow(_ lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
static func remainderWithOverflow(_:_:)

Divide lhs and rhs, returning the remainder and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func remainderWithOverflow(_ lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)
static func subtractWithOverflow(_:_:)

Subtract lhs and rhs, returning a result and a Bool that is true iff the operation caused an arithmetic overflow.

Declaration

static func subtractWithOverflow(_ lhs: Int, _ rhs: Int) -> (Int, overflow: Bool)

Instance Methods

func advanced(by:)

Returns a Self x such that self.distance(to: x) approximates n.

If Stride conforms to Integer, then self.distance(to: x) == n.

Complexity: O(1).

Declaration

func advanced(by n: Int) -> Int

Declared In

SignedInteger
func distance(to:)

Returns a stride x such that self.advanced(by: x) approximates other.

If Stride conforms to Integer, then self.advanced(by: x) == other.

Complexity: O(1).

Declaration

func distance(to other: Int) -> Int

Declared In

SignedInteger
func toIntMax()

Represent this number using Swift's widest native signed integer type.

Declaration

func toIntMax() -> IntMax