Swift Bindings won't work Xcode 6 Beta 5

前端 未结 3 2039
生来不讨喜
生来不讨喜 2021-01-04 08:52

I\'m doing a simple test program using bindings in Swift on OSX. Having an NSTableView, NSArrayController and a model class I try to hook them up together, but without succe

相关标签:
3条回答
  • 2021-01-04 09:32

    You have to select the Table View Cell and bind it's value to Table Cell View with the appropriate objectValue. I don't know how to get rid of the exclamation-mark / warning, but it works.

    enter image description here

    0 讨论(0)
  • 2021-01-04 09:32

    Are you using NSCell or NSView based tables? How you set up bindings is different for these. What you are doing looks correct for NSCell based tables.

    When I set up a NSTableView today, it was a NSView based table, so I had to select the TextField and bind to "Table Cell View" with a Model Key Path "objectValue.name"

    See the Table View Programming Guide for Mac: Populating a Table View Using Cocoa Bindings documentation

    0 讨论(0)
  • 2021-01-04 09:34

    Beta 5 requires you to explicitly set your properties as dynamic in order for KVO/bindings to work:

    dynamic var firstName = "Brook"
    

    See the Dynamic declaration modifier section of the release notes for more information.

    The dynamic keyword enables KVO, proxying, and other advanced Cocoa features to work reliably with Swift declarations.

    0 讨论(0)
提交回复
热议问题