Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use "floor" in swift

Tags:

ios

swift

var viewSize = Double(viewersView.frame.size.width)
var itemSize = Double(boxSize + viewerHorizontalPadding)
self.maxViewers = floor(viewSize / itemSize) //should be Int

I get an error that says:

No "floor" candidates produce expected contextual result type "Int"

I imported Darwin.

like image 314
TIMEX Avatar asked Apr 13 '16 05:04

TIMEX


1 Answers

floor takes a Double and returns another Double. If you want it to be an Int (to match self.maxViewers, you must convert it explicitly: Int(floor(viewSize / itemSize)).

like image 187
jtbandes Avatar answered Oct 19 '22 10:10

jtbandes