lampShade
lampShade

Reputation: 4391

How do I sort an NSArrayController by string length using bindings?

I'm trying to use a key-path to sort an NSTableView by the length of each string contained in each row. I'm using an NSArrayController to control my content array, but I'm having trouble finding out where or how to get the array controller to perform this behavior. I know the setting is in Interface Builder somewhere; I just can't find it.

Upvotes: 0

Views: 860

Answers (1)

sys 64738
sys 64738

Reputation: 197

In Interface Builder, select your table column and view its Attributes in the Inspector. Enter your key path in the Sort Key field. For example, if you want to sort by the length of string foo, set Sort Key to foo.length (this works because strings have a length method). Then set the Selector field to compare:

Upvotes: 4

Related Questions