- www.haiku-os.org / www.mobileinteraction.se
- @konrad1977
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
func login() { | |
do { | |
let token = try loginUserWithUsername("konrad1977", password: nil) | |
print("user logged in \(token)") | |
} catch LoginError.EmptyUsername { | |
print("empty username") | |
} catch LoginError.EmptyPassword { | |
print("empty password") | |
} catch { |
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
func loginUserWithUsername(username: String?, password: String?) throws -> String { | |
guard let username = username where username.characters.count != 0 else { | |
throw LoginError.EmptyUsername | |
} | |
guard let password = password where password.characters.count != 0 else { | |
throw LoginError.EmptyPassword | |
} | |
///Handle all the other, | |
return "token:" + username |
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
enum LoginError : ErrorType { | |
case EmptyUsername | |
case EmptyPassword | |
} |
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
enum TextCase { | |
case Uppercase(String) | |
case Lowercase(String) | |
} | |
let values: [TextCase] = [ | |
.Uppercase("FOO"), | |
.Lowercase("iamlow"), | |
.Uppercase("BAR"), | |
] |
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
enum CustomError : ErrorType { | |
case ErrorWithMessage(message: String) | |
} | |
func loginUserWithName(username: String?) throws -> String { | |
guard let username = username where username.characters.count != 0 else { | |
throw CustomError.ErrorWithMessage(message: "No username provided") | |
} | |
return "token:" + username |
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
func greetingsForOptionals(name: String?) { | |
guard let unwrappedName = name where unwrappedName.characters.count != 0 else { | |
return | |
} | |
print("Greetings \(unwrappedName)") | |
} | |
var name: String? = "FooBar" | |
greetingsForOptionals(name) |
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
var index = 0 | |
repeat { | |
index++ | |
} while index < 100 |
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
var daysInMonth: Int = 30 | |
var currentYear: 2000 | |
let months: 12 | |
enum Sex { | |
case Male | |
case Female | |
case Unknown | |
} |
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
func getWelcomeMessageToUser(user: String) -> String { | |
return "Hello " + user | |
} |
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
func myFirstFunction() { | |
let message = "hello world!" | |
print(message) | |
} |