Implicit conversion of a non-Objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC

ⅰ亾dé卋堺 提交于 2019-12-10 20:10:54

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26519429/implicit-conversion-of-a-non-objective-c-pointer-type-char-to-nsstring-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!