我一直在尝试建立<条码> 查询<<> > 查询/编码>,该代码也配备了手稿。 我宣读了。 问题并知道如何做到这一点。
我只问关闭部分。
1) I know I can write : {alert in println("Foo")}
Or {_ in println("Foo")}
but I can t write {println("Foo")}
. In the comments here it is explained because you need to handle the argument action.
这是否意味着,由于手稿是“条码”的类型(即“危险行动”)——“沃德”? 我必须始终抓住已经通过的警示行动吗?
2)
I also read this and the answer is basically saying you can pass in a function as your argument, but the function should take something of type UIAlertAction -> Void
, which I wrote :
private func anything(action : UIAlertAction) {
print("hello")
}
接着,我提醒大家注意:
let anotherAction = UIAlertAction(title: "hi", style: UIAlertActionStyle.Default,
handler: anything(action)) // error: Use of unresolved identifier action
混淆了我为何得出这一错误
3) In the comments it also said: But in addition to that you don t have to write UIAlertActionStyle.Default in swift. .Default works, too
我试图写字不使用风格,因此将不成<代码>。 Default
let sendLogAction = UIAlertAction(title: "Log") { action in print("goodbye")}
但当时我有以下错误:
(title: String, (_) -> ()) (aka (title: String, _ -> ()) ) is not convertible to (title: String?, style: UIAlertActionStyle, handler: ((UIAlertAction) -> Void)?) (aka (title: Optional, style: UIAlertActionStyle, handler: Optional ()>) ), tuples have a different number of elements
4)
Also reading this answer. I don t understand why we need to pass in alert
it makes no sense. It s not like we don t know what are alert s type is...haven t we already defined its type?!! Can anyone explain where passing the action itself would be useful in general, I mean what could we do with it?
我知道这4个问题,但我认为这确实是一个基本问题。 我已广泛使用,在“Im”项目中使用了关闭/复合处理器,在游乐场工作,但我仍然混淆不清。