I'm just trying out implementing a category in my Obj-C project and I'm having a small glitch.
I have a class, Map, with a .h and .m file.
I have a class Map+LineOfSight that is a Category.
Here's the code in Map+LineOfSight.h:
(There are some other methods declared, but they're not relevant.)
And in Map+LineOfSight.m:
(Again, the other methods have been left out.)
Then, in another class, "MapView", I import Map.h:
Create a pointer to the Map object that was created by yet another class, "GameData".
And finally, I have this method:
This code runs perfectly. But the glitch is that when I build the project, the line:
generates a warning:
Is there a way to eliminate the warning? When the program runs, Map responds to the method just fine. Am I not importing or forward referencing something that I should be? How does the Map class even know about the LineOfSight category?
Thanks,
Newbie Greg
I have a class, Map, with a .h and .m file.
I have a class Map+LineOfSight that is a Category.
Here's the code in Map+LineOfSight.h:
Code:
#import "Map.h"
@interface Map ( LineOfSight )
- (NSDictionary *)visibleHexesFrom:(Hex *)hex withinRange:(int)range;
@end
And in Map+LineOfSight.m:
Code:
#import "Map+LineOfSight.h"
#import "Hex.h"
@implementation Map ( LineOfSight )
- (NSDictionary *)visibleHexesFrom:(Hex *)hex withinRange:(int)range
{
...do stuff...
return visibleHexes;
}
@end
Then, in another class, "MapView", I import Map.h:
Code:
#import "Map.h"
Create a pointer to the Map object that was created by yet another class, "GameData".
Code:
- (void)prepareForNewMap
{
map = gameData.map;
...do some other stuff...
}
And finally, I have this method:
Code:
- (void)setHexYouAreHere:(Hex *)hex;
{
hexYouAreHere = hex;
[visibleHexes removeAllObjects];
[visibleHexes addEntriesFromDictionary:[map visibleHexesFrom:hex withinRange:SIGHT_RANGE]];
}
@end
This code runs perfectly. But the glitch is that when I build the project, the line:
Code:
[visibleHexes addEntriesFromDictionary:[map visibleHexesFrom:hex withinRange:SIGHT_RANGE]];
Code:
'Map' may not respond to '-visibleHexesFrom:withinRange:'
Is there a way to eliminate the warning? When the program runs, Map responds to the method just fine. Am I not importing or forward referencing something that I should be? How does the Map class even know about the LineOfSight category?
Thanks,
Newbie Greg