mercredi 31 décembre 2014

Swift Bug or Coding Error? For Loops in Structs

So I am trying to make an iOS app that checks prime numbers in an input field as practice. I refactored my code to have a struct specifically for calculation functions like isPrime. For some reason my for loops is not working correctly when its in the struct. It works if I refactored it back into the controller.



func isPrime(number:Int) -> Bool{
let start = 2
for var i = number-1; i > 1; i-- {
if (number % i == 0){
return true
}
}
return false
}


The debugger thingy gives back these inputs: Types 12 into text field




number = 12


i = 14070095816392014214




Why is my variable i in the for loops so damn large? I also tested putting a stray variable inside the function and it does the same thing (ex; start_int = 14214124123232423)?




Aucun commentaire:

Enregistrer un commentaire