Swift 中的块显示错误 "Missing argument for parameter #2 in call"
Blocks in Swift shows error "Missing argument for parameter #2 in call"
我现在在我的项目中使用 Jonas Gessner 的 JGActionSheet 和 Swift,当我试图将块转换为 [=32] 时,示例是由 Objective-C 编写的=],Xcode显示错误"Missing argument for parameter #2 in call",这里是我写的代码和截图:
Objective-C样本
JGActionSheet *sheet = [JGActionSheet actionSheetWithSections:sections];
[sheet setButtonPressedBlock:^(JGActionSheet *sheet, NSIndexPath *indexPath)
{
[sheet dismissAnimated:YES];
}];
我写的代码Swift
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock {
(sheet: JGActionSheet!, indexPath: NSIndexPath!) in
actionSheet.dismissAnimated(true)
}
截图错误
Missing argument for parameter #2 in call
所以请帮我解决这个问题,非常感谢!
actionSheet.buttonPressedBlock
是一个 属性。您正在尝试设置它。那么你的等号在哪里?这就是您在 Swift:
中设置内容的方式
myThing.myProperty = myValue
您试图将此 属性 设置为一个块(一个函数)这一事实没有任何改变。所以:
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock = {
(sheet: JGActionSheet!, indexPath: NSIndexPath!) in
actionSheet.dismissAnimated(true)
}
我现在在我的项目中使用 Jonas Gessner 的 JGActionSheet 和 Swift,当我试图将块转换为 [=32] 时,示例是由 Objective-C 编写的=],Xcode显示错误"Missing argument for parameter #2 in call",这里是我写的代码和截图:
Objective-C样本
JGActionSheet *sheet = [JGActionSheet actionSheetWithSections:sections];
[sheet setButtonPressedBlock:^(JGActionSheet *sheet, NSIndexPath *indexPath)
{
[sheet dismissAnimated:YES];
}];
我写的代码Swift
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock {
(sheet: JGActionSheet!, indexPath: NSIndexPath!) in
actionSheet.dismissAnimated(true)
}
截图错误
Missing argument for parameter #2 in call
所以请帮我解决这个问题,非常感谢!
actionSheet.buttonPressedBlock
是一个 属性。您正在尝试设置它。那么你的等号在哪里?这就是您在 Swift:
myThing.myProperty = myValue
您试图将此 属性 设置为一个块(一个函数)这一事实没有任何改变。所以:
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock = {
(sheet: JGActionSheet!, indexPath: NSIndexPath!) in
actionSheet.dismissAnimated(true)
}