Crazy Croutons

“Y'all need to get your shit together! You hear me, humans? Your shit is all outta whack! You're all over the place like a bunch of crazy croutons and tomatoes in a crazy salad!” *



Patrick Renner's
public bookmarks on weird stories, beautiful products, loud music and stunning images.


flickr.com/photos/iptrk

Twitter Logo twitter.com/iptrkpm

Pomfort Logo
pomfort.com   

Multiple Selection for NSArrayController and Cocoa Bindings

For the records:

Say you have a master-detail pattern between Playlist and Song objects, both are shown in NSTableViews. Now if you select mutliple playlists, you want all the songs from all selected lists being merged together and displayed in the songs table.

Q: What bindings do I need for that? I tried a lot during the last hour and always got exceptions or an empty song table!

A: Bind the songs’ NSArrayController’s:

  • “Managed Object Context” to your one Managed Object Context,
  • “Content Set” to your playlists NSArrayController,
    Controller Key: selection and
    Model Key Path: songs and
  • “Content Array for Multiple Selections” to your playlists NSArrayController,
    Controller Key: selection and
    Model Key Path: @distinctUnionOfArrays.songs.
(in accordance to that Apple article).

This solution is not really obvious, but if everything else is set up right, you should now get the desired merging-for-multiple-selection behavior.