非目标C指针类型“char *”到“NSString *”的隐式转换不允许使用ARC [英] Implicit conversion of a non-Objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC

查看:1758
本文介绍了非目标C指针类型“char *”到“NSString *”的隐式转换不允许使用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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆