开发者

return from incompatible pointer types

The below code generates the incompatible pointer type error:

char *PLURAL(int objects, NSString *singluar, NSString *pluralised) {
return objects ==1 ? singluar:pluralised;}

I am new 开发者_Python百科to objective-C and programming in general so can some one help me with this error?


An NSString * is not the same as a char * (or "C-string" in Objective C terminology). You can't convert a pointer from one to the other implicitly like that. You'll have to use a method like cStringUsingEncoding. Also, NSString is immutable, so you'll have to return a const char *.

Alternatively, you could simply return the NSString * instead of char *.


Change the return value to NSString* and you should be fine. You are specifying a return value of char* but actually returning NSString*.


Change it to:

NSString *PLURAL(int objects, NSString *singluar, NSString *pluralised) {
    return objects ==1 ? singluar:pluralised;
}

char * is not NSString !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜