TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
A simple Objective-C wrapper for the Forecast.io API version 2.
Additional support features:
The code base comes with two examples:
And here is a very basic example:
#import "AppDelegate.h"
#import "Forecast.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[Forecast sharedInstance] initializeWithApiKey:@"FORECAST_APIKEY"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[TopViewController alloc] init]];
[self.window makeKeyAndVisible];
return YES;
}
fetch currently forecast data using Current location:
#import "TopViewController.h"
#import "Forecast.h"
#import "ForecastApi.h"
#import "ForecastData.h"
@interface TopViewController ()
@end
@implementation TopViewController
- (void)viewDidLoad
{
[super viewDidLoad];
ForecastApi* api = [ForecastApi sharedInstance];
[api getCurrentDataForCurrentLocation:^(ForecastData *data) {
NSLog(@"%@", data.temperature);
NSLog(@"%@", data.icon);
} failure:^(NSError *error) {
NSLog(@"%@", error);
}];
}
@end
fetch currently forecast data using Address:
#import "TopViewController.h"
#import "Forecast.h"
#import "ForecastApi.h"
#import "ForecastData.h"
@interface TopViewController ()
@end
@implementation TopViewController
- (void)viewDidLoad
{
[super viewDidLoad];
ForecastApi* api = [ForecastApi sharedInstance];
[api getCurrentDataForAddress:@"yokohama, kanagawa" success:^(ForecastData *data) {
NSLog(@"%@", data.temperature);
NSLog(@"%@", data.icon);
} failure:^(NSError *error) {
NSLog(@"%@", error);
}];
}
@end
fetch daily forecast data using current location:
#import "TopViewController.h"
#import "Forecast.h"
#import "ForecastApi.h"
#import "ForecastData.h"
@interface TopViewController ()
{
UITableView* _tableView;
NSMutableArray* _dataSource;
}
@end
@implementation TopViewController
- (void)viewDidLoad
{
[super viewDidLoad];
ForecastApi* api = [ForecastApi sharedInstance];
[api getDailyDataForCurrentLocation:^(NSMutableArray *responseArray) {
_dataSource = [responseArray mutableCopy];
[_tableView reloadData];
} failure:^(NSError *error) {
NSLog(@"%@", error);
}];
}
@end
Essentially, this code is free to use in commercial and non-commercial projects with no attribution necessary.
See the LICENSE
file for more details.