在obj c中声明为未使用的标识符,即使它已声明

时间:2014-08-28 14:33:14

标签: objective-c ios7 xcode5 nsdictionary undeclared-identifier

我遇到了NSDictionary for循环的问题。这本词典被称为“海滩”,但在循环海滩内是未申报的。这是代码

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];


NSArray *results = [jsonString JSONValue];


for (NSDictionary *beach in results);             //beach is flagged as unused
{
  NSString *Name = [beach objectForKey:@"Name"];  //beach is flagged as undeclared
  NSLog(Name);
}

}

任何建议都会很棒。

1 个答案:

答案 0 :(得分:2)

您的for声明中有一个虚假的分号:

for (NSDictionary *beach in results); 
//                                  ^

这使您的代码等同于:

for (NSDictionary *beach in results)
    ;

{
    NSString *Name = [beach objectForKey:@"Name"];
    NSLog(Name);
}