I have a structure in one ViewController which has a couple of non-optional members like:
struct MyStruct {
let id: Int64!
let name: String!
func checkValues() -> Bool {
if id == nil || name == nil {
return false
} else {
print("id: \(id) name: \(name)"); return true
}
}
}
I create an instance of the struct in another VC (let temp = ViewController.MyStruct(id: 10, name: "Example")
) and pass it to the one where I created the struct via a Segue. When executing temp.checkValues()
I get
id: Optional(10) name: Optional("Example")
From my understanding of (non-)optionals I shouldn't get the Optional()
since I declared the variables with !
. Did I get it wrong? Right now I just put an exclamation mark whenever I use it. I also tried using init
in the struct but that didn't change anything.
Since this is not as intended (if I'm right) I fear I didn't get the full concept... Please tell me what is wrong with my code / me.