Basic Observation Request

Request observation data for a single location and display certain field values in text labels. The subviews have been setup as IBOutlets in the view controller.

MyViewController.h

@interface MyViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *tempTextLabel;
@property (weak, nonatomic) IBOutlet UILabel *weatherTextLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;

@end

MyViewController.m

#import <Aeris/Aeris.h>

@implementation MyViewController

- (void)viewDidAppear:(BOOL)animated {
	[super viewDidAppear:animated];

	AWFPlace *place = [AWFPlace placeWithCity:@"minneapolis" state:@"mn" country:@"us"];
	AWFObservationsLoader *loader = [[AWFObservationsLoader alloc] init];

	[loader getObservationForPlace:place options:nil completion:^(NSArray *objects, NSError *error) {
		if (error) {
			NSLog(@"Observation data failed to load! %@", error);
			return;
		}

		if ([objects count] > 0) {
			AWFObservation *obs = (AWFObservation *)[objects objectAtIndex:0];

			self.tempTextLabel.text = [NSString stringWithFormat:@"%i%@", [obs.tempF integerValue], AWFDegree];
			self.weatherTextLabel.text = obs.weather;
			self.iconImageView.image = [AWFImage weatherIconNamed:obs.icon];
		}
	}];
}

@end

MyViewController.swift

let place = AWFPlace(city: "minneapolis", state: "mn", country: "us")
let loader = AWFObservationsLoader()

loader.getObservationFor(place, options: nil) { (objects, error) in
	if let error = error {
		print("Observation data failed to load! \(error)")
		return
	}
	
	if let obs = objects?.first as? AWFObservation {
		tempTextLabel.text = "\(obs.tempF.intValue)"
		weatherTextLabel.text = obs.weather
		
		if let icon = obs.icon {
			iconImageView.image = AWFImage.weatherIconNamed(icon)
		}
	}
}

Last modified: November 02, 2017