3

I have a view (created in a StoryBoard) that has a couple of NSTextFields and a slider control. I have one NSTextField that that takes the value of the another NSTextField and a sliderValue.

When I click the "Add" button (which is connected to the add: action of the array controller) all the values are added...except the value in the NSTextField with the "computed value". I can type in that field manually, and it works. Have looked on this site, apple documentation, and general google searches, but I'm not sure why I cannot add this data to the array controller. More details (code)...

NSTextField: Name **Gets added**
SliderValue: Grade **Gets added**
NSTextField: gradebookName  **Only adds if manually typed in**

Code:

    var txtGradeBookName: String
    let sliderValueString = String(sender.integerValue)

    txtGradeBookName = txtName.stringValue + "GradeBook" + sliderValueString
    gradebookName.stringValue = txtGradeBookName

The ArrayController is bound to a Core Data model. Again, txtName and the Slider value gets added no problem...but gradebookName never gets added (unless I manually type it in)...and it's binding is set up identical to the the other two.

Code Different
  • 90,614
  • 16
  • 144
  • 163
  • Possible duplicate of [Swift: Cocoa binding value to a computed property does not work](http://stackoverflow.com/questions/35892657/swift-cocoa-binding-value-to-a-computed-property-does-not-work) – Willeke Aug 21 '16 at 12:06
  • 1
    Why do you use an arraycontroller? Usually it is used with a table view. – Willeke Aug 21 '16 at 16:41
  • I used the arraycontroller because it appears that what Apple recommends in their documentation related to bindings in OSX. – MattEarlySwift Aug 22 '16 at 15:56
  • It appears that Apple only has documentation about binding a table view to an array controller. If you handle one object at a time, use `NSObjectController`. The `add:` method commits the changes to the current object and adds an new empty object. When do you calculate `gradebookName`? – Willeke Aug 22 '16 at 23:37

0 Answers0