Created
May 13, 2019 09:24
-
-
Save nhathm/0310d049ea0494c5cd00eb0f59d8b57f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
struct Car { | |
var id: Int | |
init?(id: Int) { | |
guard id > 0 else { | |
return nil | |
} | |
self.id = id | |
} | |
func checkSystemWhenStart() throws -> String { | |
// If have error then return error message | |
// Else return empty string | |
// Case can't check system health, throws | |
return "" | |
} | |
} | |
let car = Car(id: 1) | |
let errorMessage = try? car?.checkSystemWhenStart() | |
print(type(of:errorMessage)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment