Incompatible pointer types sending 'NSString *' to parameter of type 'NSInteger *' (aka 'int *')
我有2个文件,data.h和data.m,具有连接db和方法db。
当我实现一种方法时,我会有一个警告
*不兼容的指针类型将'NSString *'发送到类型为'NSInteger *'的参数(又名'int')
这是我的代码。
在data.h中
1 2 | - (id)initCity:(NSString *)pathDB: (NSInteger *)id_city: (NSString *)type; - (void)getCity:(NSString *)dbPath:(NSInteger *)id_city; |
在data.m
1 2 3 4 5 6 7 8 9 | - (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 { ....... ...... } |
以及我在哪里调用我的方法
1 2 3 | NSString *mystring = @"string"; dataCity = [[Data alloc] initCity: defaultDBPath: selectedItem :mystring]; NSMutableDictionary *dictionary = [dataCity objectAtIndex:0]; |
哪里错了?
谢谢
坦率
首先,NSInteger是整数类型,而不是对象,因此不需要指针。
其次,您的方法声明格式错误。应该是这样的:
1 2 | - (id)initCityWithPath:(NSString *)pathDB andId:(NSInteger)id_city andType:(NSString *)type; - (void)getCityWithPath:(NSString *)dbPath andId:(NSInteger)id_city; |
1 | - (id)initCity:(NSString *)pathDB: (NSInteger *)id_city: (NSString *)type; |
此方法的名称为
其次,初始化方法应始终从调用
第三,您的初始化程序调用
这里没有冒犯的意图,但是从您上面提供的代码看来,您似乎对Objective-C的基本方面缺乏了解。我建议阅读一本好书,跟随一些著名的教程,并在继续之前先看一下苹果的一些示例代码。
1:对于较早的运行时,在