Ios 你的意思是什么印刷品()';斯威夫特?
嗨,我刚开始学斯威夫特。我只是学习ios开发的初学者Ios 你的意思是什么印刷品()';斯威夫特?,ios,iphone,swift,cocoa-touch,Ios,Iphone,Swift,Cocoa Touch,嗨,我刚开始学斯威夫特。我只是学习ios开发的初学者 func showOkay() { let title = NSLocalizedString("a title", comment: "") let message = NSLocalizedString("msg", comment: "") let cansal = NSLocalizedString("cancel", comment: "") let ok = NSLocalizedString("o
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
如果我使用print()
只会给我类似的错误
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
无法将类型为“()->()”的值转换为所需的参数类型“((UIAlertAction)->Void)?”
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
此语句使用尾部闭包语法。{
和}
之间的东西实际上是一个闭包,它被传递给UIAlertAction
,稍后在事件发生时调用。调用闭包时,它将被传递创建的UIAlertAction
对象
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
let cancelAlertAction = UIAlertAction (title : cansal , style : .cancel) {
_ in print("cancel") \\ i don't understand this line . its just a print or somthing else . why i cant use print here.
}
如果您不打算使用警报操作,则需要中的\uuu告诉Swift您忽略了UIAlertAction
,并且对其不做任何操作。你是说,我知道有一个参数,但我忽略了它
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
如果未在
中指定,Swift将推断您的闭包类型为()->()
类型,这意味着它不获取任何内容,也不生成任何内容。这与您希望提供的闭包类型不匹配,闭包类型为(UIAlertAction)->Void
(采用UIAlertAction
,但不返回任何内容)
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
通常是这样写的:
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
let cancelAlertAction = UIAlertAction (title : cansal , style : .cancel) { _ in
print("cancel")
}
这更清楚地表明,
中的\uuuu是闭包参数语法,与print
语句没有直接关系。此语句使用尾部闭包语法。{
和}
之间的东西实际上是一个闭包,它被传递给UIAlertAction
,稍后在事件发生时调用。调用闭包时,它将被传递创建的UIAlertAction
对象
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
let cancelAlertAction = UIAlertAction (title : cansal , style : .cancel) {
_ in print("cancel") \\ i don't understand this line . its just a print or somthing else . why i cant use print here.
}
如果您不打算使用警报操作,则需要
中的\uuu告诉Swift您忽略了UIAlertAction
,并且对其不做任何操作。你是说,我知道有一个参数,但我忽略了它
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
如果未在
中指定,Swift将推断您的闭包类型为()->()
类型,这意味着它不获取任何内容,也不生成任何内容。这与您希望提供的闭包类型不匹配,闭包类型为(UIAlertAction)->Void
(采用UIAlertAction
,但不返回任何内容)
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
通常是这样写的:
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
let cancelAlertAction = UIAlertAction (title : cansal , style : .cancel) { _ in
print("cancel")
}
这更清楚地表明,
中的\是闭包参数语法,与print
语句没有直接关系
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}