0% found this document useful (0 votes)
881 views1 page

Swift Cheat Sheet

Types, variables, and strings can represent different data in Swift including integers, floats, doubles, Booleans, and strings. Classes allow defining custom types with properties and methods while structures are value types that can encapsulate related properties and behaviors. Common control flow constructs like if/else, for loops, and switches allow conditionally executing code. Arrays and dictionaries provide ways to store and access multiple values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
881 views1 page

Swift Cheat Sheet

Types, variables, and strings can represent different data in Swift including integers, floats, doubles, Booleans, and strings. Classes allow defining custom types with properties and methods while structures are value types that can encapsulate related properties and behaviors. Common control flow constructs like if/else, for loops, and switches allow conditionally executing code. Arrays and dictionaries provide ways to store and access multiple values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Types Variables Strings

Int 1, 25, 589, 30_000 let iAmAConstant : Int = 42 var combi = "\(string1)
Float 1.6, 6.89, 4.6789, 3.14159 var iAmAVariable : Int = 23 + \(string2)"
Double 3.1415925359 later... iAmAVariable = 46 let numberString = "2"
Bool true, false var inferredVariable = "I'm a string" var integer
String "Angela", "Philipp" var optionalString:String? = nil =numberString.toInt

Classes Methods Arrays + Dict


let one = "Uno"
class myClass:someSuperClass { func myMethod() -> Bool {
let two = "Dos"
var myProperty:Int? return true } var array : [String]
override init() { func methodWithParam (a:Int, b:int) { = ["one", "two"]
a+b array.append("Tres")
myProperty = 12
print("two = \(array[1]")
} //methods } }
var dict :
If + For Loops Switch Dictionary [String: Int] =
["One": 1, "Two": 2]
if someCondition == true { //do x switch someVariable {
dict["Two"] = "Dos"
} else { //do y } case 1: "Hello" dict["One"] = nil //=delete
for var i = 0 ; i < 4 ; i++ { //do smthin} case 2: "Good Bye" for (string, number) in dict{ }

for i in 0...4 { //do something else } default: "Nothing" }


for i in 0..<4 {//do another thing }

You might also like