0

I have two errors here. I'm trying to get a UIAlertView that comes up when the button is pressed. From there, I want the user to input a new number (Double) and then have it update the variable timeWorkedGoal as well as the timeWorkedGoalNumber label.

I'm getting the error "Use of unresolved identifier 'UIKeyboardTypeNumberPad'" as well as the error "Reference to property 'timeWorkedGoalNumber' in closure requires explicit 'self'. to make capture semantics explicit." Does anybody know how my syntax is off? Thanks!

var timeWorkedGoal = 1.1 @IBOutlet weak var timeWorkedGoalNumber: UILabel! @IBAction func resetTimeWorkedGoalButton(sender: AnyObject) { var timeWorkedAlert = UIAlertController(title: "Time Worked", message: "Your current work time goal is \(timeWorkedGoal) hours – Enter your new goal.", preferredStyle: UIAlertControllerStyle.Alert) timeWorkedAlert.addTextFieldWithConfigurationHandler { (textField) in } timeWorkedAlert.addAction(UIAlertAction(title: "Submit", style: .Default, handler: { (action) in let textF = timeWorkedAlert.textFields![0] as UITextField print(textF) textF.keyboardType = UIKeyboardTypeNumberPad; timeWorkedGoal = (Double("\(textF)"))! print(timeWorkedGoal) timeWorkedGoalNumber.text = "\(textF)" })) timeWorkedAlert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: { (action) in self.dismissViewControllerAnimated(true, completion: nil) })) self.presentViewController(timeWorkedAlert, animated: true, completion: nil) } 

2 Answers 2

2

Error "Use of unresolved identifier 'UIKeyboardTypeNumberPad'"

Use textF.keyboardType = UIKeyboardType.NumberPad

Reference to property 'timeWorkedGoalNumber' in closure requires explicit 'self'

Explains itself. Instead of just using timeWorkedGoalNumber use self.timeWorkedGoalNumber

also you need to update timeWorkedGoal = (Double("\(textF)"))! to self.timeWorkedGoal = (Double("\(textF)"))!

EDIT: textF is a type of UITextField so cannot be directly cast to a Double. Insted you can use textF.text that will return you a String. So you will have something like this Double("\(textF.text)")

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the solution. I'm still getting the following error. i.imgur.com/CfanKyi.png
0

First Question:

textF.keyboardType = UIKeyboardType.UIKeyboardTypeNumberPad 

Second Question:

Add

self.timeWorkedGoal = (Double("\(textF)"))! 

instead it was previously

timeWorkedGoal = (Double("\(textF)"))! 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.