I have this simple class:
import UIKit
let builtIn = MyClass(n1: 1)
print("DeviceA: \(builtIn.n1)") // DeviceA Optional(1)
class MyClass: NSObject {
var n1: Int!
init(n1: Int) {
super.init()
self.n1 = n1
}
}
Why is it DeviceA Optional(1)
on the console while n1
is not optional?
I could fix this by print("DeviceA: \(builtIn.n1!)")
. But I just don't understand why Optional
is there.
Thanks,