ios 从“int”分配给“int *”的不兼容整数到指针转换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5293406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Incompatible integer to pointer conversion assigning to 'int *' from 'int'
提问by Preston
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 值的行上收到警告,它说Incompatible intiger to pointer conversion assigning to 'int *' from 'int'.
我应该怎么做才能解决这个问题?
回答by occulus
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 中, anint
是一种原始数据类型。你已经写了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.com/~tjensen/ptr/pointers.htm
回答by Gajendra K Chauhan
Yes, simply remove asterisk (*
) from declaration.
是的,只需*
从声明中删除星号 ( )。
for example.declare BOOL isCheckedinstead of BOOL * isChecked.
例如.declare BOOL isChecked而不是BOOL * isChecked。
回答by Rob
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
}
回答by Riwels
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。