Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

GregX999

macrumors newbie
Original poster
Apr 5, 2009
18
0
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:

Code:
#import "Map.h"

@interface Map ( LineOfSight )

- (NSDictionary *)visibleHexesFrom:(Hex *)hex withinRange:(int)range;

@end
(There are some other methods declared, but they're not relevant.)

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
(Again, the other methods have been left out.)

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]];
generates a warning:
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
 
You need to import the header for the category as well into classes you call category methods from.

I'm not that familiar with category stuff, but i would think importing the category header instead would suffice, since it should already be importing the class on which it is a category. Is this true?

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.