我想在 swift 函数的参数名称之间添加一个空格。我想在 swift 提供的 prepare for segue 函数中实现类似的东西
func prepare(for segue: UIStoryboardSegue, sender: Any?)
实现函数调用时使用的“for segue”参数名称。
例如。我想创建一个函数 func saveReceipt(for customer:....)
然后我想调用函数 saveReceipt(for customer:....)
最佳答案
可悲的是,参数并不是这样工作的。
以 prepareForSegue
函数为例。它看起来像这样作为一个函数:
override prepare(for segue: ...) {
但是,如果你要调用它,它看起来像这样:
prepare(for: UIStoryboardSegue, ...)
当你调用一个函数时,你只能有一个参数名称。
编辑
看看你的例子,你可以有一个这样的函数:
func saveReceipt(for customer: ...) {
然后这样调用它:
saveReceipt(for: MyCustomerClass, ...)
关于ios - swift 函数参数名称中的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41871428/