• 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: Type comparison warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Type comparison warning
      • From: "Clark Cox" <email@hidden>
References: 
 >Type comparison warning (From: DKJ <email@hidden>)

  • Prev by Date: Re: -[_NSZombie methodSignatureForSelector:] not working
  • Next by Date: RE: Porting from Windows to Mac
  • Previous by thread: Re: Type comparison warning
  • Next by thread: Re: Type comparison warning
  • Index(es):
    • Date
    • Thread