Beware of hidden NSTableView columns in Leopard (user defaults name clash)

  • Just a little heads-up:

    In one of my applications, users are given the possibility to hide
    NSTableView columns. To remember those hidden columns, I had put them
    in a dictionary (key: column id; value: archived column) and stored
    them in my application's user defaults with the following key:

    [NSString stringWithFormat: @"NSTableView Hidden Columns %@", [self
    autosaveName]]

    Back when I implemented this feature, I thought it was nice to name my
    settings similar to how I imagined Apple would name them.

    Now, after updating to Leopard, my application kept crashing when
    retrieving those stored columns. They had somehow automagically turned
    into an empty NSArray -- instead of the NSDictionary my application
    had stored in the user defaults.

    It took me a while to find out why, but it turns out that Leopard's
    new isHidden/setHidden NSTableColumn feature uses the exact same
    settings key I had chosen. And Apple stores an array for that key.

    So before anyone else wastes his time on the same thing, two warnings
    are in order, I think:

    1. Starting with Leopard, the system uses the "NSTableView Hidden
    Columns <AutoSaveName>" user defaults key. If you have been using it,
    you'll have to adapt.

    2. Generally speaking, don't try to do what you think Apple would do.
    If you get it half-right, as I did, you'll be in trouble.

    Cheers,

    Peter.
  • >
    > [NSString stringWithFormat: @"NSTableView Hidden Columns %@", [self
    > autosaveName]]
    >
    > Back when I implemented this feature, I thought it was nice to name
    > my settings similar to how I imagined Apple would name them.
    >
    > Now, after updating to Leopard, my application kept crashing when
    > retrieving those stored columns. They had somehow automagically
    > turned into an empty NSArray -- instead of the NSDictionary my
    > application had stored in the user defaults.
    >
    > It took me a while to find out why, but it turns out that Leopard's
    > new isHidden/setHidden NSTableColumn feature uses the exact same
    > settings key I had chosen. And Apple stores an array for that key.
    >
    > So before anyone else wastes his time on the same thing, two
    > warnings are in order, I think:
    >
    > 1. Starting with Leopard, the system uses the "NSTableView Hidden
    > Columns <AutoSaveName>" user defaults key. If you have been using
    > it, you'll have to adapt.
    >
    > 2. Generally speaking, don't try to do what you think Apple would
    > do. If you get it half-right, as I did, you'll be in trouble.

    Yeah, sorry about that! Generally, things stored in the user defaults
    that begin with "NS" are reserved for Apple use (as you discovered).
    It is also good to avoid method names that we "might" use, like
    "isHidden/setHidden" on NSTableColumn. The easiest way to avoid these
    type of conflicts is to use some unique prefix of your own. If you are
    targeting your app on Tiger and Leopard, you can do some
    "respondsToSelector:@selector(isHidden)" checks, and use the built in
    logic if available, or your own logic (or, opt to always use your own
    no matter what).

    --corbin
  • On Oct 30, 2007, at 5:57 AM, Peter Maurer wrote:

    > So before anyone else wastes his time on the same thing, two
    > warnings are in order, I think:
    >
    > 1. Starting with Leopard, the system uses the "NSTableView Hidden
    > Columns <AutoSaveName>" user defaults key. If you have been using
    > it, you'll have to adapt.
    >
    > 2. Generally speaking, don't try to do what you think Apple would
    > do. If you get it half-right, as I did, you'll be in trouble.

    Excellent advice. In my own code, I don't create defaults key names,
    class or variable names, or anything else beginning with NS.

    sherm--

    Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    Cocoa programming in Perl: http://camelbones.sourceforge.net
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today