In Swift 2.2, I often declared variables using a concise syntax similar to let x = UIView?()
. This gave x
the UIView?
type, and initialised it with nil
. (Of course, you could use any type instead of UIView
in these examples)
However, when I do the same in Swift 3.0, I get an error:
Cannot invoke initializer for type 'UIView?' with no arguments
. It also says that Overloads for 'UIView?' exist with these partially matching parameter lists: (Wrapped), (nilLiteral: ())
. Somehow, I don't think UIView?(nilLiteral: ())
is quite what I'm after.
Naturally, there are other alternative methods to do the same thing, such as let x: UIView? = nil
and let x = nil as UIView()
, but they're more verbose than the method I was using previously. Was the UIView?()
constructor removed in Swift 3.0, or has it been replaced in a form that I've not yet discovered?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…