Swift Cheat Sheet

swift-og

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 {
}


image host

Vineet Srivastav is the founder of Vineet Geek. He is a tech blogger, developer and gadget freak.


Similar Articles

0 Comments

Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

2022 Vineet Geek | All Rights Reserved | Developed By Vineet Srivastav