Skip to content

Instantly share code, notes, and snippets.

@agibson73
Created December 23, 2016 17:42
Show Gist options
  • Save agibson73/75a83f115502d809f756a6cb47988003 to your computer and use it in GitHub Desktop.
Save agibson73/75a83f115502d809f756a6cb47988003 to your computer and use it in GitHub Desktop.
#import "SettingsViewController.h"
#import "HomeViewController.h"
#import "AppDelegate.h"
#import "Location+CoreDataClass.h"
#import "LocationManager.h"
#import "DarkSkyAPI.h"
@interface SettingsViewController ()<UISearchBarDelegate>
@property(strong, nonatomic) NSMutableArray* searchedLocation;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@end
@implementation SettingsViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.searchBar.delegate = self;
}
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSLog(@"%@", self.tabBarController.viewControllers.firstObject);
__weak typeof(self) bruce = self;
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder geocodeAddressString:searchBar.text completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
__strong typeof(bruce) hulk = bruce;
if(placemarks.count > 0) {
CLLocation *location = placemarks.lastObject.location;
CLLocation *newLocation = location;
NSLog(@"newLocation %@",newLocation);
[[LocationManager sharedManager] setCurrentLocation:newLocation];
NSArray *viewControllers = [hulk.tabBarController viewControllers];
NSLog(@"The location is %@",location);
[DarkSkyAPI fetchCurrentWeatherWithCompletion:^(Weather *weather) {
__strong typeof(bruce) hulk = bruce;
NSLog(@"the weather is %@",weather);
HomeViewController *homeView = (HomeViewController *)viewControllers[0];
homeView.currentWeather = weather;
[[NSNotificationCenter defaultCenter]
postNotificationName:@"WeBeFinished"
object:self];
NSLog(@"The weather is %@",weather.temperature);
[self.tabBarController setSelectedIndex:0];
}];
}
}];
// AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
// NSManagedObjectContext *context = appDelegate.persistentContainer.viewContext;
//
// NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Location"];
// request.predicate = [NSPredicate predicateWithFormat:@"Location.locationName == %@", _searchBar.text];
//
// NSError *error;
// NSArray *results = [context executeFetchRequest:request error:&error];
//
// if(!error){
// NSLog(@"RESULTS: %@", results);
// }
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
// [self.view endEditing:YES];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment