• 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: Tell which type is in NSValue?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tell which type is in NSValue?


  • Subject: Re: Tell which type is in NSValue?
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 5 Aug 2009 09:27:50 +0100

On 5 Aug 2009, at 09:15, aaron smith wrote:

thanks for the info. I'm trying to put it all together. help me out?

I've tried a couple diff things, here's what Im trying..

if([test objCType] == @encode(NSPoint)) printf("test is an NSPoint");

AFAIK @encode(), unlike @selector(), doesn't try to make the string it returns unique. So I'm guessing you aren't seeing your "test is an NSPoint" message? (You don't say...)


You probably want

  if (strcmp ([test objCType], @encode(NSPoint)) == 0)
    printf ("test is an NSPoint");

or similar.

Make sure you read the type encodings docs, because there are some gotchas; for instance, typedefs have no representation in the type encoding, so two structures whose members' *base types* are equal will have the same type encoding.

Usually when you're using NSValue, you already know what type you're dealing with. If you have a situation where you need to distinguish between several different things, you might be better off making some wrapper classes (or maybe subclasses of NSValue, which is how NSNumber works).

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

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: Tell which type is in NSValue?
      • From: Graham Cox <email@hidden>
References: 
 >Tell which type is in NSValue? (From: aaron smith <email@hidden>)
 >Re: Tell which type is in NSValue? (From: Bill Bumgarner <email@hidden>)
 >Re: Tell which type is in NSValue? (From: aaron smith <email@hidden>)

  • Prev by Date: Re: Tell which type is in NSValue?
  • Next by Date: Re: Main Event queue
  • Previous by thread: Re: Tell which type is in NSValue?
  • Next by thread: Re: Tell which type is in NSValue?
  • Index(es):
    • Date
    • Thread