Joe Shamuraq
Joe Shamuraq

Reputation: 1385

Issue with NSDictionary

I have a function to convert html symbol from strings and then insert them into NSDictionary. I guess its probably method or syntax error.

Function to convert html value:

  - (NSString *)convertMathSymbol:(NSString *)str{

         str = [str stringByReplacingOccurrencesOfString:@"−" withString:@"− "];
         str = [str stringByReplacingOccurrencesOfString:@"÷" withString:@"÷ "];
         str = [str stringByReplacingOccurrencesOfString:@"&multiply;" withString:@"× "];

         return str;
    }

inserting into NSDictionary:

 NSString *tempAns1 = [[sample objectAtIndex:0]objectAtIndex:1];
 [answer setObject:[[self convertMathSymbol:tempAns1] forKey:@"1"]];

Error:

No visible @interface for 'NSString' declares the selector 'forKey:'

Appreciate any pointers... Thanx in advance...

Upvotes: 0

Views: 1714

Answers (3)

D.C.
D.C.

Reputation: 15588

Your brackets on the second line are not balanced. you have 3 ['s and 2 ]'s.

Upvotes: 2

CodaFi
CodaFi

Reputation: 43330

You are sending a message to an NSString*, let me show you how.

You have:

 [answer setObject:[[self convertMathSymbol:tempAns1] forKey:@"1"];

Strip away the answer dictionary receiver, and you get:

 [[self convertMathSymbol:tempAns1] forKey:@"1"];

See what I mean?

Try:

 [answer setObject:[self convertMathSymbol:tempAns1] forKey:@"1"];

Upvotes: 3

Andrew Madsen
Andrew Madsen

Reputation: 21383

Change this

[answer setObject:[[self convertMathSymbol:tempAns1] forKey:@"1"];

to this:

[answer setObject:[self convertMathSymbol:tempAns1] forKey:@"1"];

You've got an extra '[' before [self convertMathSymbol:tempAns1' which is confusing the compiler. The way you've written it, you're sending a message forKey: to the result of [self convertMathSymbol:tempAns1]. Pretty simple...

Upvotes: 2

Related Questions