class Circle {
var x: Double , y: Double
var radius: Double
init!(radius: Double) {
x = 0.0
y = 0.0
if radius<=0 { self.radius = 1.0}
self.radius = radius
}
}
let circle = Circle(radius: 10.0)
print(circle.radius)
Swift compiler complains: Value of optional type 'Circle?' must be unwrapped to refer to member 'radius' of wrapped base type 'Circle'.
Does init! mean implicit unwrapped optional? So we do not need ?.
I can’t recall another example of someone using init!, and didn’t even recall that this is a supported feature in Swift. Out of curiosity, why are you using init! here in the first place?