Why won't the warning method be detected?

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

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

no 'initWithCoordinate: title' method found?

+3
source share
2 answers

As Johannes said, you must declare a method in the class header file.

If you do not use the method outside 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” an existing class with new methods. Since you declare it in the source file (.m) instead of the header file (.h), it will be visible only to the code in this source file.

+4

( MapPoint - framework?), , .

, (clean + build). XCode .

+4

Source: https://habr.com/ru/post/1747980/


All Articles