This is a simple class I wanted to have instantiated with two arrays to populate an NSTableView on a mac app:
class TableController: NSObject, NSTableViewDataSource, NSTableViewDelegate {
var paintingNames:[String]
var paintingKeys:[String]
init(names:[String], keys:[String]) {
paintingNames = names
paintingKeys = keys
// breakpoint here shows both arrays have values
}
...
}
When I step through the code as it is being initialized, everything works up to this point. Then I get this error:
"fatal error: use of unimplemented initializer 'init()' for class..."
So I can can avoid this error, by adding the arrays optionals (not what I want as they are the tableView's dataSource) and adding an override init() call:
class TableController: NSObject, NSTableViewDataSource, NSTableViewDelegate {
var paintingNames:[String]?
var paintingKeys:[String]?
override init() { // this gets called after the first custom init function
// a breakpoint here shows the arrays are now both nil
}
init(names:[String], keys:[String]) { //this gets called first
paintingNames = names
paintingKeys = keys
// breakpoint here shows both arrays have values
}
...
}
Without the nil check on the arrays in the override init() call, the arrays are nil. Even with this bit of logic added:
override init() { // this gets called after the first custom init function
if paintingNames != nil {
paintingNames = [String]()
}
if paintingKeys != nil {
paintingKeys = [String]()
}
}
they are still nil.
What is going on here?