例如,
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{ (x:UIAlertAction) in
...
会出现“找不到初始值设定项...”错误。
但如果我说UIAlertAction!
或UIAlertAction?
而不只是UIAlertAction
,那就行了。为什么是这样?
答案 0 :(得分:0)
The types of these variables are all declared already in the Cocoa API. You must match them. A thing and an Optional wrapping that thing are not a match; they are two completely different types.
On the other hand, when types are known you can just omit them. So the easiest thing is for you to change x:UIAlertAction
to simple x
or even _
.