Reputation: 315
I wrote a function that looks like this:
- (void)changeText:(NSUInteger)arrayIndex;
Let's just say that's a method in the class Label. Let's say I have an array of Label objects. I call the function like this:
[[labels objectAtIndex:0] changeText:1];
or like this:
NSUInteger index = 1;
[[labels objectAtIndex:0] changeText:index];
Why does it give me the warning: Passing argument 1 of 'changeText:' makes pointer from integer without a cast
? The code executes fine.
*EDIT*
Calling the function these ways does not give a warning:
[[labels objectAtIndex:0] changeText:0]; //arrayIndex is 0
Label *object = [labels objectAtIndex:0];
[object changeText:1];
Upvotes: 2
Views: 2361
Reputation: 1716
Somehow it thinks that changeText: takes a pointer as an argument. Probably because objectAtIndex: returns an NSObject and Objective-C doesn't know, a priori, what class's signature to apply to it.
Why don't you assign the result of objectAtIndex: to a Label*, then apply changeText: to it?
Like so: Label* label = (Label *)[labels objectAtIndex:0]; [label changeText:1];
Upvotes: 2
Reputation: 162722
More likely than not, you aren't #import
ing the header file containing the definition of changeText:
into whatever .m
file is calling it and, thus, the compiler hasn't seen the method declaration and doesn't know what the argumentation is supposed to be.
Or you have a changeText:
method defined that does take an object reference as an argument and the compiler is seeing that before compiling the call site.
Upvotes: 5