A signed integer value type.
SDK
- Xcode 6.0.1+
Framework
- Swift Standard Library
Declaration
@frozen struct Int
Overview
On 32-bit platforms, Int is the same size as Int32, and on 64-bit platforms, Int is the same size as Int64.
A signed integer value type.
SDK
Framework
@frozen struct Int
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 If Needed: 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?(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>) -> IntReturns a random value within the specified range.
static func random<T>(in: Range<Int>, using: inout T) -> IntReturns a random value within the specified range, using the given generator as a source for randomness.
static func random(in: Closed Range<Int>) -> IntReturns a random value within the specified range.
static func random<T>(in: Closed Range<Int>, using: inout T) -> IntReturns a random value within the specified range, using the given generator as a source for randomness.
Perform arithmetic and bitwise operations or compare values.
func negate()Replaces this value with its additive inverse.
func quotient And Remainder(dividing By: Int) -> (quotient: Int, remainder: Int)Returns the quotient and remainder of this value divided by the given value.
func is Multiple(of: Int) -> BoolReturns true if this value is a multiple of the given value, and false otherwise.
These methods return the result of an operation, and a flag indicating whether the operation overflowed the bounds of the type.
func adding Reporting Overflow(Int) -> (partial Value: 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 Reporting Overflow(Int) -> (partial Value: 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 Reporting Overflow(by: Int) -> (partial Value: 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 Reporting Overflow(by: Int) -> (partial Value: 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 Reporting Overflow(dividing By: Int) -> (partial Value: 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.
func multiplied Full Width(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 Full Width((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: UIntThe magnitude of this value.
typealias Int .MagnitudeA type that can represent the absolute value of any possible value of this type.
func abs<T>(T) -> TReturns the absolute value of the given number.
func signum() -> IntReturns -1 if this value is negative and 1 if it’s positive; otherwise, 0.
static var zero: IntThe zero value.
static var min: IntThe minimum representable integer in this type.
static var max: IntThe maximum representable integer in this type.
static var is Signed: BoolA Boolean value indicating whether this type is a signed integer type.
var byte Swapped: IntA representation of this integer with the byte order swapped.
var little Endian: IntThe little-endian representation of this integer.
var big Endian: IntThe 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: IntThe number of bits used for the underlying binary representation of values of this type.
var bit Width: IntThe number of bits in the binary representation of this value.
var nonzero Bit Count: IntThe number of bits equal to 1 in this value’s binary representation.
var leading Zero Bit Count: IntThe number of leading zeros in this value’s binary representation.
var trailing Zero Bit Count: IntThe number of trailing zeros in this value’s binary representation.
var words: Int .WordsA collection containing the words of this value’s binary representation, in order from the least significant to most significant.
struct Int .WordsA type that represents the words of this integer.
These initializers create an integer with the bit pattern of the memory address of a pointer or class instance.
init<P>(bit Pattern: P?)Creates a new value with the bit pattern of the given pointer.
init(bit Pattern: Object Identifier)Creates an integer that captures the full value of the given object identifier.
init(bit Pattern: Opaque Pointer?)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: StringA textual representation of this value.
var hash Value: IntThe hash value.
func hash(into: inout Hasher)Hashes the essential components of this value by feeding them into the given hasher.
var custom Mirror: MirrorA mirror that reflects the Int instance.
init?(from: MLData Value)Creates an integer from another integer wrapped in a data value.
var data Value: MLData ValueThe integer wrapped in a data value.
static var data Value Type: MLData Value .Value TypeThe underlying type an integer uses when it wraps itself in a data value.
init()Creates a new value equal to zero.
init(integer Literal: Int)Creates an instance initialized to the specified integer value.
typealias Int .Integer Literal TypeA type that represents an integer literal.
func distance(to: Int) -> IntReturns the distance from this value to the given value, expressed as a stride.
func advanced(by: Int) -> IntReturns a value that is offset the specified distance from this value.
var custom Playground Quick Look: _Playground Quick LookA custom playground Quick Look for the Int instance.
init(NSNumber)Deprecatedstruct Int .SIMD2StorageStorage for a vector of two integers.
struct Int .SIMD4StorageStorage for a vector of four integers.
struct Int .SIMD8StorageStorage for a vector of eight integers.
struct Int .SIMD16StorageStorage for a vector of 16 integers.
struct Int .SIMD32StorageStorage for a vector of 32 integers.
struct Int .SIMD64StorageStorage for a vector of 64 integers.
typealias Int .StrideA type that represents the distance between two values.
var identifier Value: MLData ValueThe integer value of the unique identifier wrapped in a data value.
struct DoubleA double-precision, floating-point value type.
struct StringA Unicode string value that is a collection of characters.
struct ArrayAn ordered, random-access collection.
struct DictionaryA collection whose elements are key-value pairs.
Solve complex problems and write high-performance, readable code.