I have some class:
@interface SearchBase : NSObject
{
NSString *words;
NSMutableArray *resultsTitles;
NSMutableArray *resultsUrl;
NSMutableArray *flag;
}
@property (copy, nonatomic) NSString *words;
- (id) getTitleAtIndex:(int *)index;
- (id) getUrlAtIndex:(int *)index;
- (id) getFlagAtIndex:(int *)index;
@end
@implementation SearchBase
- (id) initWithQuery:(NSString *)words
{
if (self = [super init])
{
self.words = words;
}
return self;
}
- (id) getTitleAtIndex:(int *)index
{
return [resultsTitles objectAtIndex:index];
}
- (id) getUrlAtIndex:(int *)index
{
return [resultsUrl objectAtIndex:index];
}
- (id) getFlagAtIndex:(int *)index
{
return [flag objectAtIndex:index];
}
@end
But when I’m trying to use some these get-methods in subclass, I see:
warning: passing argument 1 of 'getTitleAtIndex:' makes pointer from integer without a cast
warning: passing argument 1 of 'getFlagAtIndex:' makes pointer from integer without a cast
warning: passing argument 1 of 'getUrlAtIndex:' makes pointer from integer without a cast
And program isn’t work correctly. What’s wrong? How to fix it?
You are passing integer values to your methods which is wrong because the functions declared by you accept only
integer pointernot value that’s the reason for having warning.andobjectAtIndex:method accept only integer value not pointer so if you run, it could cause crash in your application.The simplest solation would be changing the parameter type in your functions.
and function implementaion could be similar to below function.