views:

634

answers:

4

I have a warning and just can't work out how to make it go away.

In my .h I have this...

-(void)restartTimer;

Then the in my .m I have...

-(void)restartTimer{
TimerViewController *TimerView = [[TimerViewController alloc]
  initWithInt:hStart
  number:mStart];

I get this error:

Warning: no '-initWithInt:number.' method found.

I am sure it is very straightforward, the code still works. If anyone can suggest any ways to solve it that would be great. Thanks

+1  A: 

This means the compiler can't find such a method at compile time. Just include the header of TimerViewController in your .m file.

Georg
By doing #import "TimerViewController.h" ? I already have that
are you sure this exact method exists in your implementation of TimerViewController?
Georg
A: 

The code still works because Objective-C allows sending messages to nil objects thus *TimerView is nil.

Eimantas
TimerView isn't actually involved at the point in time the method is invoked.
bbum
+1  A: 
-(void)restartTimer{
    TimerViewController *TimerView = [[TimerViewController alloc]
        initWithInt:hStart
             number:mStart];
...
}

(1) TimerView should be timerView, as per Objective-C naming conventions

(2) Your TimerViewController.h should have a declaration something like:

- (TimerViewController *) initWithInt: (NSInteger) hStart number: (NSInteger) mStart;

(assuming that you want hStart and mStart to be integers).

(3) You must import TimerViewController.h in the implementation file that the above code appears in, either directly or indirectly (because it is imported by something else, potentially the project's PCH file).

(4) A better name for the method might be:

- (TimerViewController *) initWithHStart: (NSInteger) hStart mStart: (NSInteger) mStart;

Or something similar -- that is, the method should describe the nature of the arguments that it takes.

bbum
A: 

Import the header file my .h will resolve this problem

GKTHEBOSS

related questions