Reputation: 31
i have 2 file, data.h and data.m with connection db and method db. When i implement a method i have a warning
*Incompatible pointer types sending 'NSString *' to parameter of type 'NSInteger *' (aka 'int ') This is my code.
in data.h
- (id)initCity:(NSString *)pathDB: (NSInteger *)id_city: (NSString *)type;
- (void)getCity:(NSString *)dbPath:(NSInteger *)id_city;
in data.m
- (id)initCity:(NSString *)pathDB: (NSInteger *)id_city: (NSString *)type
{
[self getCity:pathDB: id_city: type];
return self;
}
- (void)getCity:(NSString *)dbPath : (NSInteger *)id_city : (NSString *)type { .......
......
}
and where i call my method
NSString *mystring = @"string";
dataCity = [[Data alloc] initCity: defaultDBPath: selectedItem :mystring];
NSMutableDictionary *dictionary = [dataCity objectAtIndex:0];
where wrong? Thanks frank
Upvotes: 1
Views: 6219
Reputation: 95315
- (id)initCity:(NSString *)pathDB: (NSInteger *)id_city: (NSString *)type;
The name of this method is initCity:::
which takes three parameters, pathDB
, id_city
and type
. This is probably not what you want and probably not what anybody who has to look at your code wants. Objective-C gives you the ability to name the parameters of methods, and any method that does not name its parameters will always be suspicious1. For most Objective-C developers, initCity:::
is not a good name for a method.
Secondly, initialiser methods should always start by invoking [super init]
and assigning the result to self
. There is seldom a reason not to do this (for example, when you are creating your own root class).
Third, your initialiser calls getCity:::
(another poor name) which returns void
and takes two input parameters and possibly one in/out or output parameter, this does not look like it will initialise your object properly. It is rare to see a method start with get
unless it has an output parameter (e.g. getBytes:length:
). In your case I think you may be using the wrong type, NSInteger
is an alias for a 32-bit integer on 32-bit platforms and a 64-bit integer on 64-bit platforms. NSInteger *
is therefore a pointer to such an integer. It's confusing, but this is different from NSNumber
which is a class that encapsulates things like NSInteger
.
No offence intended here, but from the code you provided above it seems that you lack some understanding of fundamental aspects of Objective-C. I would recommend reading a good book, following some reputable tutorials and having a look at some of Apple's example code before progressing.
1: For older runtimes, the root Object
class declared in objc/Object.h
had two methods called forward::
and performv::
which both contained an unnamed parameter, and these were used for message forwarding.
Upvotes: 2
Reputation: 16124
First of all NSInteger is an integer type, not an object, so you don't need a pointer.
Secondly, your method declarations are malformed. It should be something like this:
- (id)initCityWithPath:(NSString *)pathDB andId:(NSInteger)id_city andType:(NSString *)type;
- (void)getCityWithPath:(NSString *)dbPath andId:(NSInteger)id_city;
Upvotes: 3