On 27/05/2010, at 8:36 PM, Ken Thomases wrote:

>       if ([obj isKindOfClass:[NSString class]])
>               // ... use 'obj' as a string
>       else if ([obj isKindOfClass:[NSArray class]])
>               // ... use 'obj' as an array
>       // ... etc. ...


It might also be worth pointing out that writing code structured in this way is 
highly indicative of a failure of design (and I say that obviously realising 
that Ken was only trying to illustrate how to discover an object's type in the 
context of the example, not how best to handle the situation as a whole).

You need to design your code so that if its type is important you can easily 
encode and decode a type indicator along with the data itself, but even then 
it's a bit of a code smell. Perhaps you just need to archive a data structure 
at a higher level so that what pops out when you dearchive is fully formed and 
ready to go, instead of needing to be sorted by type and handled accordingly?


--Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to