Home Ask Login Register

Developers Planet

Your answer is one click away!

Quantic Dreams February 2016

Swift 2 arc4random_uniform crash?

I have a very simple execution, but it's crashing for some reason. Any ideas why?

import UIKit  
class ViewController: UIViewController {

@IBOutlet var myTextField: UITextField!
@IBOutlet var resultsLabel: UILabel!

@IBAction func pressButton(sender: AnyObject) {
    let diceRoll = String(arc4random_uniform(UInt32(6)))
    print(diceRoll)
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

Crash Log added

2016-02-06 16:24:32.358 GuessingGame[6330:496415] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key TextField.' * First throw call stack: ( 0 CoreFoundation 0x000000010960ae65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010b34adeb objc_exception_throw + 48 2 CoreFoundation 0x000000010960aaa9 -[NSException raise] + 9 3 Foundation 0x00000001099d39bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 4 UIKit 0x0000000109fb6320 -[UIViewController setValue:forKey:] + 88 5 UIKit 0x000000010a1e4f41 -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x000000010954b4a0 -[NSArray makeObjectsPerformSelector:] + 224 7 UIKit 0x000000010a1e3924 -[UINib instantiateWithOwner:options:] + 1864 8 UIKit 0x0000000109fbceea -[UIViewController _loadViewFromNibNamed:bundle:] + 381 9 UIKit 0x0000000109fbd816 -[UIViewController loadView] + 178 10 UIKit 0x0000000109fbdb74 -[UIViewController loadViewIfRequired] + 138 11 UIKit 0x0000000109fbe2e7 -[UIViewController view] + 27 12 UIKit 0x0000000109e94ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61 13 UIKit 0x0000000109e95199 -[UIWindow _setHidden:forced:] + 282 14 UIKit 0x00000001

Answers


Alain T. February 2016

Most likely cause is that you renamed your IBOutlet from TextField to myTextField in your code (or added a new link but did not remove the old reference from the control in IB).

Post Status

Asked in February 2016
Viewed 3,988 times
Voted 7
Answered 1 times

Search




Leave an answer


Quote of the day: live life