Incompatible pointer to integer conversion initializing 'NSInteger' (aka 'long') with an expression of type 'id _Nullable'
时间: 2023-06-20 16:07:04 浏览: 386
这个编译错误通常是因为试图将一个 `id` 类型的对象赋值给一个 `NSInteger` 类型的变量,这两个类型不兼容。
要解决这个问题,需要确定你的代码中哪个变量被错误地声明为 `NSInteger` 类型,并且尝试将其更改为适当的类型。
另外,也可以尝试使用类型转换来将 `id` 类型的对象转换为适当的类型,例如:
```
id obj = // some object
NSInteger num = (NSInteger)obj;
```
但是,这种方法只在你确信 `obj` 对象实际上是一个 `NSInteger` 类型时才可用。否则,它可能会导致其他类型的错误。
相关问题
Incompatible pointer to integer conversion initializing 'char' with an expression of type 'char[20]'
This error message occurs when you try to initialize a variable of type 'char' with an array of characters (also known as a string) instead of a single character.
For example, if you try to do this:
char myChar = "hello";
You will get the error message because "hello" is a string of characters, not a single character.
To fix this error, you can either use a single character instead of a string, like this:
char myChar = 'h';
Or you can use a pointer to the string instead of the string itself, like this:
char* myString = "hello";
char myChar = myString[0]; // assigns the first character of the string to myChar
incompatible pointer to integer conversion initializing 'char' with an expression of type 'char[5]' [-Wint-conversion]
在初始化时使用类型为 'char[5]' 的表达式来初始化 'char' 类型的变量,导致指针与整数类型不兼容的转换。这可能是因为您正尝试将一个字符数组赋值给一个字符变量。要解决这个问题,您可以考虑使用字符串复制函数(如 strcpy)来将字符数组的内容复制到字符变量中,或者使用正确的数据类型来存储字符数组的内容。
阅读全文
相关推荐















