-2

Any anyone explain the syntax in adding two or more textfields together in Swift 3 inside XCode 8. This is for a desktop application, not IOS. NSTextField Control.

I need precision to the tenth's place. So I guess a float will be necessary.

Furthermore, how can I do the adding automatically when the textbox is updated, so it is adding on the fly. So I do not have to put in a "Calculate" button. Do I need to do anything special to sanitize the fields to prevent alphas to be typed?

  • You should post the code for what you've tried so far. Also, you may need to clarify. Looks like you're trying to add the numerical version of the contents of text fields. Not the text fields themselves. Pedantic yes. But it matters. – Son of a Beach Dec 11 '16 at 21:20
  • from what I can tell, they discontinued .toInt() in XCode 8 and Swift 3 and you cannot just use the + sign to add the strings together. As far as events and listeners, I tried several codes, and it looks like in the newer version they have removed the GUI to add event listeners, you now have to add them progmatically. I'm honestly not sure on adding the textboxes at all. I'm trying to learn as much as I can here. Tried a google search for items listed this year. Could you at least kindly point me to an example if one exists. Maybe I'm not using the right search terms. – Sean Lyons Dec 11 '16 at 22:51
  • You may ask basic questions only after going through basic stuff like https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html . – El Tomato Dec 11 '16 at 22:54
  • `class View1Controller: NSViewController { @IBAction func txtJudgeA(_ sender: Any) { txtJudgeScore1.textDidChange(newJudgeScore) } func newJudgeScore(notification: NSNotification) { dialogOKCancel(question: "Ok?", text: "New Judge Score"); } }` But I get the compile error Cannot Convert Value of Type (NSNotification) to expected argument type Notification – Sean Lyons Dec 11 '16 at 23:40

1 Answers1

0

Not the most helpful group. Here's what I found out works. added NSTextFieldDelegate to the top View Class Controller like so class View1Controller: NSViewController, NSTextFieldDelegate

Then: in my viewdidload txtField.delegate = self Then I could override the function:

override func controlTextDidChange(_ obj: Notification) { run some code here }