在Swift中,我試圖使用max()和min()函數。iOS Swift max(),min()
max<T : Comparable>(x: T, y: T, rest: T...) -> T
min<T : Comparable>(x: T, y: T, rest: T...) -> T
我試圖使用MAX()函數以這種方式:
var paddleX: Int = Int(paddle.position.x) + Int(location.x - previousLocation.x)
max(paddleX, paddle.frame.x/2, nil)
,但我收到此錯誤:
Cannot convert the expression's type of '()' to type 'NilType'
是在nil
造成這個問題? rest: T...
應該是什麼?
描述的最小/最大內置於Swift中。由於聲明包含在問題中,我認爲這是一個自定義實現的機會。 –