You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.5 KiB
Plaintext

// Swift 4 builtin data types:
//
// * Int or UInt (Int32, Int64, UInt32, UInt64)
// * Float
// * Double
// * Bool
// * String
// * Character
// * Optional a variable that can hold either a value or no value.
// * Tuples
//
// | -------|-------------------|-----------------------------------------------|
// | Type | Typical Bit Width| Typical Range |
// | -------|-------------------|-----------------------------------------------|
// | Int8 | 1byte | -127 to 127 |
// | UInt8 | 1byte | 0 to 255 |
// | Int32 | 4bytes | -2147483648 to 2147483647 |
// | UInt32 | 4bytes | 0 to 4294967295 |
// | Int64 | 8bytes | -9223372036854775808 to 9223372036854775807 |
// | UInt64 | 8bytes | 0 to 18446744073709551615 |
// | Float | 4bytes | 1.2E-38 to 3.4E+38 (~6 digits) |
// | Double | 8bytes | 2.3E-308 to 1.7E+308 (~15 digits) |
// | -------|-------------------|-----------------------------------------------|
6 years ago
// Type Aliases:
//
6 years ago
typealias Feet = Int
var distance: Feet = 100
print(distance)
// Type inference:
//
// varA is inferred to be of type Int
6 years ago
var varA = 42
print(varA)
//
// varB is inferred to be of type Double
6 years ago
var varB = 3.14159
print(varB)
//
// varC is also inferred to be of type Double
6 years ago
var varC = 3 + 0.14159
print(varC)