【问题标题】:Identifier declared as unused in obj c, even though it is declared在 obj c 中声明为未使用的标识符,即使它已声明
【发布时间】:2014-08-28 14:33:13
【问题描述】:

我遇到了 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);
}

}

任何建议都会很棒。

【问题讨论】:

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


    【解决方案1】:

    您的 for 语句中有一个虚假的分号:

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

    这使您的代码等效于:

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

    【讨论】:

    • 不错,不敢相信我错过了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 1970-01-01
    相关资源
    最近更新 更多