Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nhathm/0310d049ea0494c5cd00eb0f59d8b57f to your computer and use it in GitHub Desktop.
Save nhathm/0310d049ea0494c5cd00eb0f59d8b57f to your computer and use it in GitHub Desktop.
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