Created
October 10, 2019 14:59
-
-
Save iannase/f6d1b8db73e5a849d35b34478815d03d to your computer and use it in GitHub Desktop.
Get warmed up to code in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// comment | |
/* multi-line | |
comment */ | |
let x = true | |
var y = false | |
let z = 1 | |
var o: String? | |
if x { | |
print("if") | |
} else if y { | |
print("else if") | |
} else { | |
print("else") | |
} | |
switch z { | |
case 1: | |
print("1") | |
case 2: | |
print("2") | |
default: | |
print("not 1 or 2") | |
} | |
if o != nil { | |
print("do something") | |
} | |
if let something = o { | |
print("\(something) is not nil") | |
} | |
var someStrings = [String]() | |
someStrings.append("Hello") | |
for string in someStrings { | |
print(string) | |
} | |
for i in 1...100 { | |
print(i) | |
} | |
for i in 1..<100 { | |
print(i) | |
} | |
func add(_ a: Int, _ b: Int) -> Int { | |
return a + b | |
} | |
let result = add(3,4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment