Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Swift max(), min()

Tags:

In Swift, I am trying to use the max() and min() functions.

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:

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'

Is the nil causing this problem? What is rest: T... supposed to be?

like image 864
junyi00 Avatar asked Jun 20 '14 06:06

junyi00


People also ask

What is MAX () and MIN ()?

The MIN() function returns the smallest value of the selected column. The MAX() function returns the largest value of the selected column.

What is Max in Swift?

max() Return Value The max() method returns the maximum element of dictionary . Note: If dictionary is empty, the method returns nil .


1 Answers

Don't pass anything at all there. It's a variadic function, you can call it with two or more parameters.

like image 62
anisoptera Avatar answered Oct 03 '22 15:10

anisoptera