class User {
var id: Int!
init(data: JSON){
id = data["id"].int
//if id doesn't exist, then cancel the init and return nil.
}
}
I want to initialize a user by passing a JSON to its constructor. However, sometimes the JSON doesn't match. In this case, I want the initialization to be cancelled, and User to be nil.