Initializer (Default implementation)swift 6.0.1Swift
init(_:)
Creates a new integer value from the given string.
init?(_ description: String)
Parameters
- description
The ASCII representation of a number.
The string passed as description
may begin with a plus or minus sign character (+
or -
), followed by one or more numeric digits (0-9
).
let x = Int("123")
// x == 123
If description
is in an invalid format, or if the value it denotes in base 10 is not representable, the result is nil
. For example, the following conversions result in nil
:
Int(" 100") // Includes whitespace
Int("21-50") // Invalid format
Int("ff6600") // Characters out of bounds
Int("10000000000000000000000000") // Out of range
Implements
init<T>(T
) Creates an integer from the given floating-point value, rounding toward zero.
init<T>(T
) Creates a new instance from the given integer.
init?(String
) Instantiates an instance of the conforming type from a string representation.
Other members in extension
Type members
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?<S>(S, radix: Int
) Creates a new integer value from the given string and radix.
init(bigEndian: Self
) Creates an integer from its big-endian representation, changing the byte order if necessary.
init<Other>(clamping: Other
) Creates a new instance with the representable value that’s closest to the given integer.
init?<T>(exactly: T
) Creates an integer from the given floating-point value, if it can be represented exactly.
init(littleEndian: Self
) Creates an integer from its little-endian representation, changing the byte order if necessary.
init<T>(truncatingIfNeeded: T
) Creates a new instance from the bit pattern of the given instance by truncating or sign-extending if needed to fit this type.
static func random(in: ClosedRange<Self>
) -> Self Returns a random value within the specified range.
static func random(in: Range<Self>
) -> Self Returns a random value within the specified range.
static func random<T>(in: ClosedRange<Self>, using: inout T
) -> Self Returns a random value within the specified range, using the given generator as a source for randomness.
static func random<T>(in: Range<Self>, using: inout T
) -> Self Returns a random value within the specified range, using the given generator as a source for randomness.
static func &* (lhs: Self, rhs: Self
) -> Self static func &*= (lhs: inout Self, rhs: Self
) Multiplies two values and stores the result in the left-hand-side variable, wrapping any overflow.
static func &+ (lhs: Self, rhs: Self
) -> Self Returns the sum of the two given values, wrapping the result in case of any overflow.
static func &+= (lhs: inout Self, rhs: Self
) Adds two values and stores the result in the left-hand-side variable, wrapping any overflow.
static func &- (lhs: Self, rhs: Self
) -> Self Returns the difference of the two given values, wrapping the result in case of any overflow.
static func &-= (lhs: inout Self, rhs: Self
) Subtracts the second value from the first and stores the difference in the left-hand-side variable, wrapping any overflow.
static func &<< <Other>(lhs: Self, rhs: Other
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width.
static func &<< (lhs: Self, rhs: Self
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width.
static func &<<= <Other>(lhs: inout Self, rhs: Other
) Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.
static func &>> <Other>(lhs: Self, rhs: Other
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width.
static func &>> (lhs: Self, rhs: Self
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width.
static func &>>= <Other>(lhs: inout Self, rhs: Other
) Calculates the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.
static func << <Other>(lhs: Self, rhs: Other
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left.
static func <<= <Other>(lhs: inout Self, rhs: Other
) static func >> <Other>(lhs: Self, rhs: Other
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the right.
static func >>= <Other>(lhs: inout Self, rhs: Other
) static func ~ (x: Self
) -> Self Returns the inverse of the bits set in the argument.
Instance members
var bigEndian: Self
The big-endian representation of this integer.
var bitWidth: Int
The number of bits in the binary representation of this value.
var littleEndian: Self
The little-endian representation of this integer.
func multipliedFullWidth(by: Self
) -> (high: Self, low: Self.Magnitude)