开发者

Newbie question -multiple parameters

开发者 https://www.devze.com 2023-03-21 19:04 出处:网络
I am trying to implement a private method which takes an NSMutableDictionary and a Player object as its parameters. As it is a private method, the only place that it exists is in the \".m\" file.

I am trying to implement a private method which takes an NSMutableDictionary and a Player object as its parameters. As it is a private method, the only place that it exists is in the ".m" file.

It is declared as

-(void) incrementScore: (NSMutableDictionary*) scoreboard  forPlayer: ( Player* ) player {

and I call it as follows :

     开发者_运维技巧 [ self incrementScore:deuceScore forPlayer:p];

However,it won't compile - I get

may not response to message -incrementScore:forplayer

I'm not sure where my error lies - do I need to declare the method in the ".h" file, or elsewhere in the ".m" file, or have I just got the syntax completely wrong?


The compiler needs to find a declaration for your method somewhere before you use it. This be done in three way:

  1. Declare the method in the (public) @interface for the class in its .h file .
  2. Declare the method in a class extension (a semi-private @interface, usually at the top of the .m files).
  3. Define the method somewhere in the @implementation before your first use of it.


This is only a warning not a compile error... (if you changed preferences to treat all warnings like error it'll be a compile error).

Probably the line calling the method is above (in the .m file) the declaration method. Move the method just below @implementation directive, or above the method with the calling line. The warning/error should disapper.

0

精彩评论

暂无评论...
验证码 换一张
取 消