views:

24

answers:

3

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 to objective-C and programming in general so can some one help me with this error?

A: 

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

Elfred
Thanks :) I have marked this as the solution since this was the first answer. @ptomato and @Felix King, thanks to you guys too :)
iSee
+3  A: 

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 *.

ptomato
A: 

Change it to:

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

char * is not NSString !

Felix Kling