Site icon Vineet Geek

Swift Cheat Sheet

Variables/Constants

var myVariable = 42
let myConstant = 12
var typedVariable: Type
let typedConstant: Type

Functions

func aFunction(input: Type) ->Type {
  //Do Something
  return theOutput
}

Data Types

Int 23 
Float 2.3 
Double 3.1415926 
Bool true/false 
String "abc" 
Array [1,2,3] 
Dictionary [key: value]

Structures

struct MyStruct {
}

Classes

class myClass: SuperClass {
 }

IF Statement

if condition {
    //do X
} elseif otherCondition {
    //do Y
} else { //do Z
}

Switch Statement

switch someVariable {
  case 1:
//do X
  case 2:
    //do X
  default:
    //do X
}

Loops

for variable in low...high {
} for fruit in fruitBasket { //do somethin
for item in array {
for i in 0...4 { //do something else }
} for i in 0..<4 {//do another thing }
while condition {
}

Exit mobile version