Skip to content

Instantly share code, notes, and snippets.

@ericcgu
Created September 20, 2014 20:57
Show Gist options
  • Save ericcgu/d62c461718a2799ade07 to your computer and use it in GitHub Desktop.
Save ericcgu/d62c461718a2799ade07 to your computer and use it in GitHub Desktop.
optional chaining
func findApt (aptNumber: String ) ->String? {
let aptNumbers = ["101", "202", "303", "404"]
for tempAptNumber in aptNumbers {
if (tempAptNumber) == aptNumber {
return aptNumber
}
}
return nil
}
func sendNoticeTo(#aptNumber:Int) {
}
if let culprit = findApt("102")?.toInt(){
sendNoticeTo(aptNumber: culprit)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment