Brian Brian - 4 months ago 23
Swift Question

Swift round function. Cannot call value of non-function type 'Int'

I'm having a strange problem.. I tried calling the round function in one of my view controllers.

let roundedValue = round( letterAmount[ index ] * 10 ) / 10


It worked fine.. When i tried using round in another view controller with the same line.

let roundedValue = round( letterAmount[ index ] * 10 ) / 10


I get the error Cannot call value of non-function type 'Int'.

I also tried doing a simple line

round( 1.2 )


The same thing happens, in one view controller i get no error but in the other i get the error Cannot call value of non-function type 'Int'.. Why is this happening?

Answer

Name collision. My guess is that your second view controller has a property named round with type of Int. Add a namespace to clarify it:

let roundedValue = Darwin.round( letterAmount[ index ] * 10 ) / 10