ios - 'UInt32' is not convertible to 'MirrorDisposition' -
edit: ok. changed code as: var randomx = int(arc4random()%6) wish think of before posting here :|
i took accepted answer of topic reference: swift convert uint int
i've been trying make simple ios guessing app swift. i'm generating random number , getting number user , comparing both. i'm stuck error: 'uint32' not convertible 'mirrordisposition'
while comparing 2 integers (one of them converted string integer toint() method)
below can see ui, code, 2 stackoverflow topics read , how changed code after reading topics.
ui: (i couldn't resize image)
my code:
import uikit class viewcontroller: uiviewcontroller { @iboutlet var myimageview: uiimageview! @iboutlet var inputfield: uitextfield! @ibaction func clickedguessbuttonaction(sender: anyobject) { println("guess button clicked") var randomx = arc4random()%6 println("randomx = \(randomx)") var guess = inputfield.text.toint() if((inputfield.text) != nil){ if(guess == randomx){ println("correct") var image = uiimage(named: "images/tick.png"); myimageview.image=image; self.view.addsubview(myimageview); // this? inputfield.resignfirstresponder();// hides keyboard } else { println("wrong") var image = uiimage(named: "images/cross.png") myimageview.image=image; self.view.addsubview(myimageview); inputfield.resignfirstresponder();//hides keyboard } } else{ println("invalid input. requires integer only") inputfield.resignfirstresponder();// hides keyboard } } override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } }
i found these topics on stackoverflow:
float not convertible 'mirrordisposition' swift mirrordisposition?
ios swift error: 't' not convertible 'mirrordisposition'
first 1 has extended answer suggesting if intvalue == int(floatvalue)
than changed var guess = inputfield.text.toint()
to var guess = int(inputfield.text);
but time i'm getting error message this: cannot invoke 'init' argument of type '@lvalue string!'
this time, searched error message couldn't find helpful. shouldn't difficult compare 2 integers. i'm missing easy. ideas?
try changing:
var randomx = arc4random()%6
to
var randomx = int(arc4random()%6)
Comments
Post a Comment