• 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: isKindofClass with NSData and NSKeyUnarchiver
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: isKindofClass with NSData and NSKeyUnarchiver


  • Subject: Re: isKindofClass with NSData and NSKeyUnarchiver
  • From: Graham Cox <email@hidden>
  • Date: Fri, 28 May 2010 10:12:38 +1000

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 (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

  • Follow-Ups:
    • Re: isKindofClass with NSData and NSKeyUnarchiver
      • From: Philip Vallone <email@hidden>
References: 
 >isKindofClass with NSData and NSKeyUnarchiver (From: Philip Vallone <email@hidden>)
 >Re: isKindofClass with NSData and NSKeyUnarchiver (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: removeObjectAtArrangedObjectIndexPath EXC_BAD_ACCESS
  • Next by Date: Re: isKindofClass with NSData and NSKeyUnarchiver
  • Previous by thread: Re: isKindofClass with NSData and NSKeyUnarchiver
  • Next by thread: Re: isKindofClass with NSData and NSKeyUnarchiver
  • Index(es):
    • Date
    • Thread