- (void)currentImageOnServer { NSURL *JSONLocation = [NSURL URLWithString:@"http://radiolight.us/Calendar/dirList.php"]; NSString *pictureLocation = [NSString stringWithFormat:@"http://radiolight.us/Calendar/"]; [[[NSURLSession sharedSession] dataTaskWithURL:JSONLocation completionHandler:^(NSData *JSONdata, NSURLResponse *response, NSError *error) { NSLog(@"%@ is the error code for currentImageOnServer", error); // Process Data NSError *jsonParsingError = nil; NSArray *filesInDirectory = [NSJSONSerialization JSONObjectWithData:JSONdata options:0 error:&jsonParsingError]; for (NSDictionary *dictionary in filesInDirectory) { NSString *fileName = dictionary[@"name"]; if ([[fileName pathExtension] isEqualToString: @"png"]) { NSString *imagePath = [pictureLocation stringByAppendingPathComponent:fileName]; nameOfFile = fileName; imageURL = imagePath; NSLog(@"imageURL is %@", imageURL); dispatch_async(dispatch_get_main_queue(), ^{ currentImageOnServerString = fileName; [self runTheFileComparison]; NSLog(@"Dictionary Deal finished, nameOfFile is now %@", nameOfFile); }); } } }] resume]; serverAlreadyChecked = YES; }