Susha
Susha

Reputation: 37

Issue with Calling Function

I have a method as follows use to correct empty values in Json

+(NSString *)CorrectJsonForEmptyValues:(NSString *)pasRawJson
{

    NSLog(@"CorrectJsonForEmptyValues");
    NSMutableString *tmpJson = [pasRawJson mutableCopy];

    [tmpJson replaceOccurrencesOfString:@"[,"
                             withString:@"[{\"v\": \"N/A\",\"f\":\"N/A\"},"
                                options:0
                                  range:NSMakeRange(0, [tmpJson length])];

    [tmpJson replaceOccurrencesOfString:@",,"
                             withString:@",{\"v\": \"N/A\",\"f\":\"N/A\"},"
                                options:0
                                  range:NSMakeRange(0, [tmpJson length])];

    NSString *correctedJson=tmpJson;
    return correctedJson;
}

Called the function like this

result = [self performSelector:@selector(CorrectJsonforEmptyvalues:) withObject:result];

But getting error

 2011-11-11 11:11:33.217 HelloWorld10[38833:207] -[Data CorrectJsonforEmptyvalues:]: unrecognized selector sent to instance 0x5725cc0
 2011-11-11 11:11:33.219 HelloWorld10[38833:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Data CorrectJsonforEmptyvalues:]: unrecognized selector sent to instance 0x5725cc0'

If any one can please provide a solution it will be helpful. Thanks in advance.

Upvotes: 0

Views: 82

Answers (2)

Minakshi
Minakshi

Reputation: 1433

You can call function as follows

        [self CorrectJsonForEmptyValues:result];

And replace the '+' in the following with '-'

    +(NSString *)CorrectJsonForEmptyValues:(NSString *)pasRawJson{

Upvotes: 1

rob mayoff
rob mayoff

Reputation: 385580

You have declared CorrectJsonForEmptyValues: as a class method by starting its declaration/definition with a + instead of a -. Therefore you call it on the class object, not on an instance of the class. If your class is named Data, for example, you call it like this:

result = [Data CorrectJsonForEmptyValues:result];

By the way, you should not start method names with capital letters.

Upvotes: 5

Related Questions