1

I'm having issues with an NSDictionary for loop. The dictionary is called 'beach' but within the loop beach is undeclared. Here's the code

- (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);
}

}

Any suggestions would be great.

Marushiru
  • 43
  • 6

1 Answers1

2

You have a spurious semi-colon in your for statement:

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

Which makes your code equivalent to:

for (NSDictionary *beach in results)
    ;

{
    NSString *Name = [beach objectForKey:@"Name"];
    NSLog(Name);
}
jlehr
  • 15,557
  • 5
  • 43
  • 45
trojanfoe
  • 120,358
  • 21
  • 212
  • 242