Can't Add Employees

I feel really stupid. I added the code on page 201, and the app seemed to be working fine, except for sorting on the name column. I remembered that a previous challenge ahd been to sort on the name length. I went back and changed the key to name and the selector to caseInsensitiveCompare: and now, I can’t add employees at all. When I click the “Add Employee” button, I get the messages

[quote]adding <RaiseMan.Employee: 0x60800005c590> to the employee array
2015-08-05 13:01:57.400 RaiseMan[2261:98694] -[_NSControllerArrayProxy firstIndex]: unrecognized selector sent to instance 0x6080000062c0
2015-08-05 13:01:57.400 RaiseMan[2261:98694] -[_NSControllerArrayProxy firstIndex]: unrecognized selector sent to instance 0x6080000062c0

2 CoreFoundation 0x00007fff92aac0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205[/quote]

When I was having a similar problem earlier, I saw the name of the unrecognized selector in these messages, but not now. I tried changing the sort key back to name.length and the selector back to compare:, but I get the same behavior. What am I forgetting to do?

The name of the unrecognized selector is shown in the error message:

-[_NSControllerArrayProxy firstIndex]
                             ^
                             |
unrecognized selector--------+

That is Objective-C syntax for calling the method firstIndex on the ArrayProxy object, which in Swift would look like:

someArrayProxy.firstIndex()

The error message is saying that the ArrayProxy does not have a method named firstIndex. Sorry, I don’t have my book in front of me right now, so that’s all I’ve got.

Thanks. I guess not knowing Objective-C is more of a handicap than I thought it would be.

The string “firstIndex” doesn’t appear in any of my Swift code. It’s got to be a problem with my bindings. As the book says, this is really hard to find. I even looked for firstIndex in Document.xib, but it’s not there, either

Zip up your project folder and post it to Dropbox or github and I’ll take a look at it for you. Not promising I can find the problem but I’ll try. :slight_smile:

@BrianLawson Thanks a lot. I really appreciate it. I put it at github.com/saulspatz/RaiseMan

The problem is with the bindings on the Table View. In the Bindings Inspector’s Table Content section all 3 bindings were set to arrangedObjects. Only the Content should be set to that. The Selection Indexes binding needs to be set to selectionIndexes and the Sort Descriptors binding should be set to sortDescriptors. Making those 2 changes will allow you to enter new employees again and sort the table.

That did it Brian, thanks so much. I wonder how these got changed. As I said, it was working, and I just changed the sorting attributes on the Name column, and it stopped working. Anyway, thanks again. I might never have found this by myself.

I’m glad it worked out Saul. I wouldn’t have found it without comparing the bindings in your code to those in mine. When I have problems like this I will do the same thing with my code and the source code provided by the authors.