Created
September 13, 2016 15:14
-
-
Save edopelawi/990735339cdef47f78b391c0455445e3 to your computer and use it in GitHub Desktop.
A sample on getting a default value for Optional with nil cases using if let and guard let statement.
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 getValidString(string: String?) -> String { | |
if let validString = string { | |
return validString | |
} else { | |
return "" | |
} | |
} | |
func anotherGetValidString(string: String?) -> String { | |
guard let validString = string else { | |
return "" | |
} | |
return validString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment