What is the modulus operator (%) in swift 3?

Kalzem picture Kalzem · Oct 27, 2016 · Viewed 42.1k times · Source

I have this line:

randomIndex = Int(drand48() % Double(alphabetColors.count))

And Xcode 8 (Swift 3) tells me:

'%' is unavailable: Use truncatingRemainder instead

Is there no operator anymore? How should I convert my code?

Answer

Logan picture Logan · Mar 29, 2017

enter image description here

This seems to be available for me, currently on Swift 3.1, so possible it was added back.

My guess is that it's somewhere in Foundation and needs an explicit import Foundation

Update

This is for Int types only. It seems that for doubles, truncating remainder is required.