views:

91

answers:

2

I have a class with a method that works and I have tested it but xcode still raises a warning over the method:

MapPoint *mp = [[MapPoint alloc] initWithCoordinate:[newLocation coordinate] 
                                              title:[locationTitleField text]];

no 'initWithCoordinate:title' method found?

+2  A: 

I can't say anything about your concrete case (is MapPoint a framework class?) but you should make sure the method is declared in an imported header file.

If that's the case and the warning still exists, try a full rebuild (clean+build). XCode's a little strange from time to time.

Johannes Rudolph
Do I need to declare each and every method in the header? What if its only used locally within the class?
TheLearner
exactly as Philipe Leybaert said. Damn, I was too slow ;-)
Johannes Rudolph
+1  A: 

As Johannes said, you should declare the method in the header file of the class.

If you are not using the method outside of the class implementation, you can create an anonymous category declaration at the top of your .m file:

@interface MapPoint()
- (id) initWithCoordinate:(MapCoordinate *)coordinate title:(NSString *)title;;
@end

An anonymous category "extends" your existing class with new methods. Since you're declaring it inside your source file (.m) instead of a header file (.h), it will only be visible to code in that source file.

Philippe Leybaert