I have the following class called User
class User: CustomStringConvertible {
var id: Int!
var firstName: String!
var lastName: String!
init(){
}
init(id: Int, firstName: String, lastName: String) {
self.id = id
self.firstName = firstName
self.lastName = lastName
}
var description: String{
return "id = \(id); first name = \(firstName); last name = \(lastName)"
}
}
I then call the class with the following code:
let user = User(id: userData["id"] as! Int, firstName: userData["first_name"] as! String, lastName: userData["last_name"] as! String)
After I call print(user)
I get the following:
id = Optional(1); first name = Optional("John"); last name = Optional("Doe")
Why is it printing Optional(1)
, Optional("John")
, when my variables are defined by Type!
. I know the answer is probably very simple however I can't figure it out. It was working fine in Swift 2.0