• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: KVC - how to get properties into a common form?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVC - how to get properties into a common form?


  • Subject: Re: KVC - how to get properties into a common form?
  • From: Graham Cox <email@hidden>
  • Date: Mon, 7 Apr 2008 09:57:28 +1000

Thanks for your thoughts,

in fact this is exactly what I ended up doing (categories on each object type of interest) and it works great. As you said Jens, for arrays, dictionaries and sets in particular there isn't a way to predict the "best" option for presentation so doing it myself was actually a benefit rather than a problem. In hindsight it seems a bit of a dumb question so thanks for your indulgence ;-)

------

G.




On 4 Apr 2008, at 2:15 am, Andy Lee wrote:
Right, it depends on your requirements for the "common form."

Rather than do a huge switch statement, you could add your own - myDescription method in a category of NSObject. It could call - description by default, and you could override it in categories of other classes you care about where -description isn't what you want.

In general, huge switch statements based on the class of an object are a good indication that you want to use inheritance, and the nice thing about categories is that you can apply extra inheritance to classes that you don't own.

--Andy

On Apr 3, 2008, at 10:54 AM, Jens Alfke wrote:


On 3 Apr '08, at 5:19 AM, Matt Gough wrote:

Is there an easy way to convert whatever <id> is into a common form (a string, in my case), or do I have to have a huge switch statement that checks the class and calls different code for each kind to convert to a string? (or similar, like an NSObject category that implements -stringValue, overridden for every class). Just wondering if there's something built-in that will do this already.


There is -description, but that probably isn't what you want.

I think it's probably the best option. For classes that have a "natural" string representation, like NSString and NSNumber, - description returns it. For others, it at least returns something readable.


The problem, Graham, is that it's ambiguous what the string representation of an arbitrary object is supposed to be. With a few exceptions as above, it tends to be pretty task-specific. Should an array look like "a, b, c", or "{a; b; c;}" or "<item>a</item> <item>b</item> <item>c</item>" or ...? So there can't be a single built-in method that does the right thing for every purpose.

—Jens_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >KVC - how to get properties into a common form? (From: Graham Cox <email@hidden>)
 >Re: KVC - how to get properties into a common form? (From: Matt Gough <email@hidden>)
 >Re: KVC - how to get properties into a common form? (From: Jens Alfke <email@hidden>)
 >Re: KVC - how to get properties into a common form? (From: Andy Lee <email@hidden>)

  • Prev by Date: Re: Objective-C Instance Variable Names
  • Next by Date: Re: Objective-C Instance Variable Names
  • Previous by thread: Re: KVC - how to get properties into a common form?
  • Next by thread: Propagate changes/insertions in main context
  • Index(es):
    • Date
    • Thread