2012-05-25 99 views
0

我有一個函數來從字符串轉換html符號,然後將它們插入NSDictionary。我猜它可能是方法或語法錯誤。問題與NSDictionary

功能轉換成HTML值:

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

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

     return str; 
    } 

插入的NSDictionary:

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

錯誤:

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

欣賞任何指針... Thanx提前...

+0

檢查tempAns1和函數返回字符串有價值... –

+0

什麼是「答案」? – saadnib

+0

答案是NSDictionary –

回答

3

發送消息給NSString *,讓我告訴你如何。

您有:

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

部分去掉答案字典接收器,你會得到:

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

明白我的意思嗎?

嘗試:

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

事實上,這應該給你一些重要的警告本身,因爲領導括號從來沒有關閉。 – CodaFi

+0

是的...我現在看到它... thanx ... –

+1

我相信這裏的其他答案值得讚賞,難道你不會說@TeamStar? – CodaFi

2

更改此

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

這樣:

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

你有一個額外的 '[' [self convertMathSymbol:tempAns1'之前,這是混淆了編譯器。你寫的方式,你發送的信息forKey:[self convertMathSymbol:tempAns1]的結果。很簡單...

2

你在第二行括號不均衡。你有3 [和2]的。