Eventually, I have succeeded to suppress the red indicator by adding @objc
to class definition like this:
@objc class Employee : NSObject {
@objc dynamic var name: String? = "New Employee"
@objc dynamic var raise: Float = 0.05
}
However, with Xcode 9 Beta, Xcode’s behaves something weird. Right after adding @objc
, Xcode struggles to find symbols and shows lots of errors at the first moment. To overcome compile errors, we might need to: Do Product > Clean. Repeatedly do Product > Build. Make some changes by adding a return key in the source file where @objc class is defined so that Xcode will recompile the source file. Wait some seconds for that Xcode’s internal cash becomes to be up-to-date.
In my humble guess, the warning message “Content Array expects to be bound to type NSObject” appears when Xcode considers the variable specified in the Model Key Path field to be inadequate. Xcode maybe solely check if the variable works with some methods defined in NSKeyValueCoding.
Confirmation failures might happen
- if the variable is not capable of NSKeyValueCoding, which NSObject has.
- if a class name of the variable cannot be found from Objective-C’s perspective of view.
- if something goes wrong during confirmation.
The warning message might be somewhat misleading, and it will be fixed in the future, I think. 
Finally, a good news!
Once @objc
is added to the class definition and @objc dynamic
is added to the array variable definition, the red indicator has gone and MVC has started to work!
Now, any modification on the variable such as adding elements, removing elements, and assigning a new value to members of elements is automatically propagated to the table view.
@objc class Employee : NSObject {
@objc dynamic var name: String?
@objc dynamic var raise: Float
}
@IBInspectable @objc dynamic var employees: [Employee] = []
NSArrayController is notified the change of the array variable, i.e. employees
, then it updates its arrangedObjects
. NSTableView is notified the change of arrangedObjects
, then it tells the change to NSTableCellView. NSTableCellView updates its objectValue
. NSTextField is notified the change of objectValue
, then it displays the new value on the screen. Amazing!
Confirmed with Xcode 9 Beta.