• 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
ObjC argument typing (was: Experimenting with Timers)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ObjC argument typing (was: Experimenting with Timers)


  • Subject: ObjC argument typing (was: Experimenting with Timers)
  • From: Ondra Cada <email@hidden>
  • Date: Mon, 22 Oct 2001 13:05:56 +0100

Isaac,

>>>>>> Isaac Sherman (IS) wrote at Sun, 21 Oct 2001 21:40:37 -0400:
IS> >1. You don't need to put the (NSTimeInterval), (SEL), (id), etc.
IS> >next to the arguments when you call the method.
IS>
IS> Thank God!! I thought they were mandatory...

Just like plain C functions: they are mandatory when you declare/define
message/method, so as compiler knew the types.

If you send the message, though, the compiler uses this knowledge to convert
arguments properly for you:

-aMethod:(float)f; // compiler knows that the argument of aMethod: is a float,...
...
[o aMethod:1]; // ...so converts here the int constant to a float properly.

You can use explicit casts in cases you do something not quite right, but
you happen to know that in this very case it _is_ right and want to get rid
of the compiler warning:

-aMethod:(NSMutableArray*)a;
...
NSArray *a=...;
// for some reason or another, I am _sure_ that (i) a is an NSMutableArray,
(ii) it is harmless here to change its contents. The reason should be very
explicitly expressed in this comment so as you will know what happens here
the next year when upgrading the code!
[o aMethod:(NSMutableArray*)a]; // without cast, the compiuler would warn

Note that such situations generally indicate bad design, and so should be
pretty rare.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc


References: 
 >Re: Experimenting with Timers (From: Isaac Sherman <email@hidden>)

  • Prev by Date: Re: Twin arrows
  • Next by Date: Drop location on the Finder?
  • Previous by thread: Re: Experimenting with Timers
  • Next by thread: Re: Dragging, IB style
  • Index(es):
    • Date
    • Thread