iOS Swift max(), min()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24321269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS Swift max(), min()
提问by junyi00
In Swift, I am trying to use the max() and min() functions.
在 Swift 中,我尝试使用 max() 和 min() 函数。
max<T : Comparable>(x: T, y: T, rest: T...) -> T
min<T : Comparable>(x: T, y: T, rest: T...) -> T
I am trying to use the max() function in this way:
我正在尝试以这种方式使用 max() 函数:
var paddleX: Int = Int(paddle.position.x) + Int(location.x - previousLocation.x)
max(paddleX, paddle.frame.x/2, nil)
but I am getting this error:
但我收到此错误:
Cannot convert the expression's type of '()' to type 'NilType'
无法将表达式的“()”类型转换为“NilType”类型
Is the nil
causing this problem? What is rest: T...
supposed to be?
是nil
造成这个问题的原因吗?什么是rest: T...
应该是什么?
回答by anisoptera
Don't pass anything at all there. It's a variadic function, you can call it with two or more parameters.
不要在那里传递任何东西。这是一个可变参数函数,您可以使用两个或多个参数调用它。