Uploaded by slxjjuqnew

Swift Cheat Sheet [Swift 5]

advertisement
Swift Cheat Sheet
Variables/Constants
var
let
var
let
myVariable = 42
myConstant = 12
typedVariable: Type
typedConstant: Type
Structures
struct MyStruct {
}
IF Statement
if condition {
//do X
} elseif otherCondition {
//do Y
} else {
//do Z
}
Functions
Data Types
func aFunction(input: Type) ->Type {
//Do Something
return theOutput
}
Classes
class myClass: SuperClass {
}
Switch Statement
switch someVariable {
case 1:
//do X
case 2:
//do X
default:
//do X
}
Int
23
Float
2.3
Double
3.1415926
Bool
true/false
String
"abc"
Array
[1,2,3]
Dictionary
[key: value]
Loops
for variable in low...high {
}
for fruit in fruitBasket { //do something
for
in {array
{
foritem
i in 0...4
//do something
else }
} for i in 0..<4 {//do another thing }
while condition {
}
www.appbrewery.co
Download