I have this code that should return the minimum value of two CGFloat values:
var boundsSize:CGSize = scrollView.bounds.size
var imageSize:CGSize = imageView.bounds.size
var xScale:CGFloat = boundsSize.width / imageSize.width
var yScale:CGFloat = boundsSize.height / imageSize.height
var minScale:CGFloat = MIN(xScale, yScale) // this does not work
But MIN does not seem to have an equivalent in swift. So how do I do this?
Try this:
var minScale = min(xScale, yScale)
min is already in swift. Hope this helps.. :)
min is variadic function. Its reset parameter is a variadic parameter. From developer site:
A variadic parameter accepts zero or more values of a specified type. You use a variadic parameter to specify that the parameter can be passed a varying number of input values when the function is called. Write variadic parameters by inserting three period characters (...) after the parameter’s type name.
For more info. See this.
The function in Swift is min, so:
var minScale = min(xScale, yScale)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With