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