Search code examples
iosobjective-cnsstringclass-extensions

NSString+Extension warning when creating a NSMutableString from self


in an iphone application I created and extension class to the NSString.

NSString+Extensions.m class

In one of the methods I need to convert the string to NSMutableString.

I tried to use this:

NSMutableString * stringToManipulate = [NSMutableString stringWithString:self];

But it is giving a warning:

Incompatible pointer types sending 'const Class' to parameter of type 'NSString *'

To my knowlede self is a reference to the string I called the method on, right? so why shouldn't it be of type NSString*? knowing that I can use the usual NSString methods on self.

Any idea on this issue?

Thanks


Solution

  • Check whether the method is declared as a class method (with the + symbol) or an instance method (with the - symbol). If its the first case, the compiler warning is normal. Turn the method to an instance one then