Re: Tell which type is in NSValue?
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