非目标C指针类型“char *”到“NSString *”的隐式转换不允许使用ARC [英] Implicit conversion of a non-Objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC
问题描述
对于下面的代码行,我得到以下错误:
for(UILabel * label in labels){
label.text = label.tag-100> someMutableString.length? :*;
}
错误状态:
使用ARC不允许非目标C指针类型char *到NSString *的隐式转换
我的变量someMutableString的类型为NSMutableString。
如何解决我的特殊情况?
<问题是你的字符串字面量是
和*
/ code>都是C风格的字符串( const char *
)。因此,右侧的类型也是 const char *
。您正在分配 UILabel
的文本
属性,该属性需要一个 NSString
。
使用 @
和 @* code>。
For the following line of code I am getting the error below:
for (UILabel *label in labels) {
label.text = label.tag - 100 > someMutableString.length ? "" : "*";
}
The error states:
Implicit conversion of a non-Objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC
My variable "someMutableString" is of type NSMutableString.
How do I fix in my particular case?
The problem is that your string literals are ""
and "*"
which are both C-style strings (const char*
). So the type of the right hand side of the assignment is also const char*
. You are assigning to the text
property of a UILabel
, which takes an NSString
.
Use @""
and @"*"
instead.
这篇关于非目标C指针类型“char *”到“NSString *”的隐式转换不允许使用ARC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!