Question

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

Was it helpful?

Solution

-(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.

OTHER TIPS

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

Import the header file my .h will resolve this problem

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top