I have yet another pesky warning I would like gone. Basically, I have an int declared like this: @property (nonatomic, assign) int *myInt;
and set like this: myInt = 0;
. It is also synthesized in the implementation file. I am getting a warning on the line where I set the int's value and it says Incompatible intiger to pointer conversion assigning to 'int *' from 'int'.
What should I do to fix this?
我还有另一个讨厌的警告想要离开。基本上,我有一个int类型声明如下:@property (nonatomic, assign) int *myInt;设为:myInt = 0;它也在实现文件中被合成。在我设置int值的行上,我得到了一个警告,它表示不兼容的intiger指针转换为“int *”,从“int”到“int”。我该怎么解决这个问题呢?
4 个解决方案
#1
56
There's a big hint in the error message!
错误消息中有一个很大的提示!
In C and Objective C, an int
is a primitive data type. You've written int *
, which means "a pointer to an int", whereas it looks like you just wanted an int.
在C和Objective C中,int是一种原始数据类型。你已经写了int *,它的意思是“指向int的指针”,而看起来你只是想要一个int。
So change your property to this:
所以把你的财产换成这个:
@property (nonatomic, assign) int myInt;
For more info, google "C pointers" and you'll find information like this: http://pw1.netcom.com/~tjensen/ptr/pointers.htm
对于更多的信息,谷歌“C指针”,你会找到这样的信息:http://pw1.netcom/ ~tjensen/ptr/pointers.htm。
#2
12
Yes, simply remove asterisk (*
) from declaration.
是的,只需从声明中删除星号(*)。
for example.declare BOOL isChecked instead of BOOL * isChecked.
例如,声明BOOL被检查,而不是BOOL *被检查。
#3
2
Another way to resolve this is to simply not declare a pointer (drop the asterisk):
解决这个问题的另一种方法是简单地不声明指针(删除星号):
@interface ViewController : UIViewController {
NSUInteger myObjcInt; // unsigned ( >= 0 ) NSObject int, yo
}
#4
1
int *MyInt
is a pointer to int, not an int.
As others told you, just remove the *
and you will have a regular int.
int *MyInt是一个指向int的指针,而不是int.正如其他人告诉你的,只要删除*,就会有一个常规的int。
#1
56
There's a big hint in the error message!
错误消息中有一个很大的提示!
In C and Objective C, an int
is a primitive data type. You've written int *
, which means "a pointer to an int", whereas it looks like you just wanted an int.
在C和Objective C中,int是一种原始数据类型。你已经写了int *,它的意思是“指向int的指针”,而看起来你只是想要一个int。
So change your property to this:
所以把你的财产换成这个:
@property (nonatomic, assign) int myInt;
For more info, google "C pointers" and you'll find information like this: http://pw1.netcom.com/~tjensen/ptr/pointers.htm
对于更多的信息,谷歌“C指针”,你会找到这样的信息:http://pw1.netcom/ ~tjensen/ptr/pointers.htm。
#2
12
Yes, simply remove asterisk (*
) from declaration.
是的,只需从声明中删除星号(*)。
for example.declare BOOL isChecked instead of BOOL * isChecked.
例如,声明BOOL被检查,而不是BOOL *被检查。
#3
2
Another way to resolve this is to simply not declare a pointer (drop the asterisk):
解决这个问题的另一种方法是简单地不声明指针(删除星号):
@interface ViewController : UIViewController {
NSUInteger myObjcInt; // unsigned ( >= 0 ) NSObject int, yo
}
#4
1
int *MyInt
is a pointer to int, not an int.
As others told you, just remove the *
and you will have a regular int.
int *MyInt是一个指向int的指针,而不是int.正如其他人告诉你的,只要删除*,就会有一个常规的int。