Re: Type comparison warning
Re: Type comparison warning
- Subject: Re: Type comparison warning
- From: Scott Ribe <email@hidden>
- Date: Thu, 30 Oct 2008 11:47:48 -0600
- Thread-topic: Type comparison warning
First off, NSInteger is an object not an int and can't be directly compared
to an int. Second, i is not likely an NSInteger, it's a pointer to an
NSInteger, which means it can be compared to an int, via implicit or
explicit casting, but in the absence of an explicit cast, the compiler
assumes that's probably not what you intended to do.
Next, NSNull & NSNumber are distinct types; the ternary operator wants both
potential returns to be of the same type (or "compatible" types for some
meaning of "compatible"), so the compiler will warn you about that once you
fix the first problem. Just cast both to id and you'll be fine--assuming the
code that receives this id properly handles the fact that it may point to
different types.
I started to say this is all basic C stuff, but that's not quite fair. It's
the intersection of Objective-C extensions with the basic C rules, which
still hold true.
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice
_______________________________________________
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