Challenge Solution Crashes

To do the challenge, I changed the attributes on the name column as follows:
Sort Key: name.length
Selector: compare:

When I click on the name problem, I get these messages on the console:

[quote]2015-07-31 19:13:59.417 RaiseMan[5089:88654] -[__NSCFNumber compare]: unrecognized selector sent to instance 0x1137
2015-07-31 19:13:59.418 RaiseMan[5089:88654] -[__NSCFNumber compare]: unrecognized selector sent to instance 0x1137
2015-07-31 19:13:59.425 RaiseMan[5089:88654] (
0 CoreFoundation 0x00007fff91baf03c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8ffd076e objc_exception_throw + 43
2 CoreFoundation 0x00007fff91bb20ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff91af7e24 forwarding + 1028
4 CoreFoundation 0x00007fff91af7998 _CF_forwarding_prep_0 + 120
5 Foundation 0x00007fff8c3e2147 _NSCompareObject + 49
6 CoreFoundation 0x00007fff91aaf27b __CFSimpleMergeSort + 75
7 CoreFoundation 0x00007fff91aaf1f5 CFSortIndexes + 549
8 CoreFoundation 0x00007fff91aeffc0 CFMergeSortArray + 240
9 Foundation 0x00007fff8c3e1c8a _sortedObjectsUsingDescriptors + 614
10 Foundation 0x00007fff8c42ebb8 -[NSMutableArray(NSKeyValueSorting) sortUsingDescriptors:] + 466
11 AppKit 0x00007fff83cf9d9b -[NSArrayController _sortObjects:] + 304
12 AppKit 0x00007fff83cf6bdb -[NSArrayController _arrangeObjectsWithSelectedObjects:avoidsEmptySelection:operationsMask:useBasis:] + 230
13 AppKit 0x00007fff83f29afd -[NSArrayController setSortDescriptors:] + 223
14 Foundation 0x00007fff8c3ade7d -[NSObject(NSKeyValueCoding) setValue:forKey:] + 395
15 Foundation 0x00007fff8c3d0901 -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 339
16 AppKit 0x00007fff83e4ff64 -[NSBinder _setValue:forKeyPath:ofObject:mode:validateImmediately:raisesForNotApplicableKeys:error:] + 360
17 AppKit 0x00007fff83e4fda3 -[NSBinder setValue:forBinding:error:] + 248
18 AppKit 0x00007fff83f24d59 -[NSTableBinder tableView:didChangeToSortDescriptors:] + 146
19 AppKit 0x00007fff83f24cb0 -[_NSBindingAdaptor tableView:didChangeToSortDescriptors:] + 153
20 AppKit 0x00007fff83e5b543 -[NSTableView setSortDescriptors:] + 228
21 AppKit 0x00007fff84246b58 -[NSTableView _changeSortDescriptorsForClickOnColumn:] + 388
22 AppKit 0x00007fff8422fc25 -[NSTableHeaderView _trackAndModifySelectionWithEvent:onColumn:stopOnReorderGesture:] + 1046
23 AppKit 0x00007fff84232992 -[NSTableHeaderView mouseDown:] + 434
24 AppKit 0x00007fff842ff2dc -[NSWindow _reallySendEvent:isDelayedEvent:] + 14125
25 AppKit 0x00007fff83c8ec86 -[NSWindow sendEvent:] + 470
26 AppKit 0x00007fff83c8b212 -[NSApplication sendEvent:] + 2504
27 AppKit 0x00007fff83bb4b68 -[NSApplication run] + 711
28 AppKit 0x00007fff83b31244 NSApplicationMain + 1832
29 RaiseMan 0x000000010000557d main + 109
30 libdyld.dylib 0x00007fff87f2d5c9 start + 1
)[/quote]

I see that javoid has posted a spoiler where he gives what seems to be exactly the same solution. Can you tell me what’s wrong? The only item that looks informative to me in the above list is number 3, “doesNotRecognizeSelector:” but I don’t know what to do about it. I tried putting the sort key in quotes: “name.length” but that didn’t work either. I got

I can duplicate your error if in the Attributes Inspector I enter:

Attributes Inspector Table Column Title: Name ... ... Sort key: name.length Selector: compare

Note that for the Selector I entered compare and not compare: (with a trailing colon).

If you are sure you entered compare: (with a trailing colon) as the selector, you might have forgotten to hit Return after entering the selector in the textbox. In any case, if you correctly enter compare: as the selector, then you should be able to get rid of your error. Quotes around the Sort key or the Selector are an error, so the entries in the Attributes Inspector should be:

Attributes Inspector Table Column Title: Name ... Sort key: name.length Selector: compare:

By the way, if you try entering xxx for the Selector, run your program, then add some employees, then click on the name column header to sort the employees, the first line of the error message will be:

In Objective-C, you call a method like this:

which in Swift would look like:

So the following error message:

is saying that some type of Number tried to call a method named xxx, and there is no method named xxx defined for the Number. In your case, the error message says:

So the error message is saying that some type of Number does not have a method named compare. See how there’s no trailing colon after compare in your error message? Next if you try entering xxx: (note the trailing colon) for the Selector, the error message will be:

Now the error message says the unrecognized selector is xxx: (with a trailing colon). Therefore, your error message tells me that you entered compare and not compare: for the Selector.

1 Like

I must have forgotten to hit , because I know I put the semicolon in. I probably left it off the first time, then added it, but didn’t hit . Thank you for the explanation of the error message. If I make this mistake again, I’ll be able to figure out what’s wrong for myself.