I try to make a Mastermind in swift but I can't get each digit of the random number using an index to check if I found a number of the code. I tried this but it's not works.. :
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var textView: UITextView!
var code = String(arc4random_uniform(9000) + 1000)
override func viewDidLoad() {
super.viewDidLoad()
println(code)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
self.view.endEditing(true)
}
@IBAction func sendDidPressed(sender: AnyObject) {
var find = 0
for (var i = 0; i < 4; i++) {
var number = textField.text
var numberInCode = map(code) { String($0) }
if contains(numberInCode, String(find)) {
find++
}
self.textView.text = "\(self.textField.text): Bien placées: \(String(find))"
}
}
@IBAction func resetCode(sender: AnyObject) {
}
}
I need help