Skip to content

Instantly share code, notes, and snippets.

@fozoglu
Created January 16, 2017 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fozoglu/80545ec4c74eaa6b56306abf80cab058 to your computer and use it in GitHub Desktop.
Save fozoglu/80545ec4c74eaa6b56306abf80cab058 to your computer and use it in GitHub Desktop.
- (IBAction)updateAction {
NSURLRequest* requestForWeatherData = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.openweathermap.org/data/2.5/weather?q=London,UK&APPID=????????????"]];
//NOTE : ???? is here -> openweathermap api key write
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:requestForWeatherData completionHandler:^(NSData * data, NSURLResponse * response, NSError * error) {
NSMutableDictionary *allData = [ NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
NSLog(@"%@ - Error %@", allData,error);
//data in serialized view
NSString* currentWeather = nil;
NSArray* weather = allData[@"weather"];
for (NSDictionary* weatherDictionary in weather) {
currentWeather = weatherDictionary[@"main"];
}
[self setImageAndTextWithWeather:currentWeather];
}];
[dataTask resume];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment