variable indirection

  • I am experimenting with the address book framework.  I made a Person
    class that acts as a wrapper around each ABPerson object.  Person uses
    valueForUndefinedKey to forward messages along to ABPerson's
    valueForProperty.  In this way I can bind to any properties (present and
    future) in each person's record from a table view.

    > From interface builder, this works fine if I bind to the name of the
    property: e.g. "First" for first name or "Last" for last.  However, the
    address book framework goes to some lengths to hide those string
    literals, and only advertises string constants such as
    kABFirstNameProperty and of course kABLastNameProperty.  So I would like
    to bind to those variable names as they are presumably more stable (and
    perhaps more localizable.)

    My most general question is: can a variable-in-a-variable be obtained in
    objective-c? Is there a better way to accomplish this, or any way that
    would continue to work in the face of apple changing the string value of
    those constants? Even if that's not particularly likely I'm still
    interested to know what's possible here.

    Thanks for any help.  I only started with cocoa/objective-c about a
    month ago so I hope I'm not missing anything terribly obvious.

    --
    Paul Phillips      | Gir! Remember with your brains... you must
    Everyman          | behave like a human dog monster.
    Empiricist        |    -- Zim
    i pull his palp!  |----------* http://www.improving.org/paulp/ *----------
  • On 22 Dec 2007, at 23:36, Paul Phillips wrote:

    > From interface builder, this works fine if I bind to the name of the
    > property: e.g. "First" for first name or "Last" for last.  However,
    > the
    > address book framework goes to some lengths to hide those string
    > literals, and only advertises string constants such as
    > kABFirstNameProperty and of course kABLastNameProperty.  So I would
    > like
    > to bind to those variable names as they are presumably more stable
    > (and
    > perhaps more localizable.)

    Those are keys, and therefore won’t be localized (you would never want
    to localize a key; you’d just make your application work badly
    whenever the user changed their language setting).

    It’s very unlikely that Apple will ever change their values, which,
    although not documented, are likely to be encoded in data stored on
    disk or transmitted over the network.

    If you’re really concerned, you could always use an NSDictionary to
    map from your own custom keys to the ones defined by the AddressBook
    framework.  Personally I don’t think I’d bother, because the risk of
    these constants changing their values seems extremely small (though
    you’re right to consider the issue, because it certainly isn’t zero).
    Moreover, doing that won’t work for newly defined keys that your
    application doesn’t know yet (and I think the risk of that is much
    greater).

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
previous month december 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