Swift
Table of Contents
Basics
Declaration
Use let
to make a constant and var
to make a variable.
var myVariable = 42
myVariable = 50
let myConstant = 42
Type Inference
implicit and explicit
let implicitInteger = 70
let implicitDouble = 70.0
let explicitDouble: Double = 70
Data Types
Int
orUInt
- You can use Int32, Int64 to define 32 or 64 bit signed integer where as UInt32 or UInt64 to define 32 or 64 bit unsigned integer variables.
Float
- 32-bit floating-point number
Double
- 64-bit float
Bool
String
Character
Optional
- Can hold either a value or no value.
Conditionals
if onSaleInferred {
print("\(nameInferred) on sale for \(priceInferred)!")
} else {
print("\(nameInferred) at regular price: \(priceInferred)!")
}