diff --git a/unit-2-assessment/unit-2-assessment.xcodeproj/project.pbxproj b/unit-2-assessment/unit-2-assessment.xcodeproj/project.pbxproj index 838d4b4..9fe4f8c 100644 --- a/unit-2-assessment/unit-2-assessment.xcodeproj/project.pbxproj +++ b/unit-2-assessment/unit-2-assessment.xcodeproj/project.pbxproj @@ -9,11 +9,16 @@ /* Begin PBXBuildFile section */ 8D6765A61BD289BC00B30411 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D6765A51BD289BC00B30411 /* main.m */; }; 8D6765A91BD289BC00B30411 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D6765A81BD289BC00B30411 /* AppDelegate.m */; }; - 8D6765AC1BD289BC00B30411 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D6765AB1BD289BC00B30411 /* ViewController.m */; }; 8D6765AF1BD289BC00B30411 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D6765AD1BD289BC00B30411 /* Main.storyboard */; }; 8D6765B21BD289BC00B30411 /* unit_2_assessment.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 8D6765B01BD289BC00B30411 /* unit_2_assessment.xcdatamodeld */; }; 8D6765B41BD289BC00B30411 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8D6765B31BD289BC00B30411 /* Assets.xcassets */; }; 8D6765B71BD289BC00B30411 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D6765B51BD289BC00B30411 /* LaunchScreen.storyboard */; }; + AB1507181BD297BA00410122 /* weatherListTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB1507171BD297BA00410122 /* weatherListTableViewController.m */; settings = {ASSET_TAGS = (); }; }; + AB15071B1BD297E600410122 /* CoordinateInputViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB15071A1BD297E600410122 /* CoordinateInputViewController.m */; settings = {ASSET_TAGS = (); }; }; + AB15071E1BD2980500410122 /* DetailWeatherViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB15071D1BD2980500410122 /* DetailWeatherViewController.m */; settings = {ASSET_TAGS = (); }; }; + AB1507211BD2981E00410122 /* APIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = AB1507201BD2981E00410122 /* APIManager.m */; settings = {ASSET_TAGS = (); }; }; + AB1507271BD2C52700410122 /* CustomWeatherTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = AB1507261BD2C52700410122 /* CustomWeatherTableViewCell.m */; settings = {ASSET_TAGS = (); }; }; + AB15072A1BD2CBD700410122 /* DailyWeatherObject.m in Sources */ = {isa = PBXBuildFile; fileRef = AB1507291BD2CBD700410122 /* DailyWeatherObject.m */; settings = {ASSET_TAGS = (); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -21,13 +26,23 @@ 8D6765A51BD289BC00B30411 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8D6765A71BD289BC00B30411 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 8D6765A81BD289BC00B30411 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 8D6765AA1BD289BC00B30411 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 8D6765AB1BD289BC00B30411 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 8D6765AE1BD289BC00B30411 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 8D6765B11BD289BC00B30411 /* unit_2_assessment.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = unit_2_assessment.xcdatamodel; sourceTree = ""; }; 8D6765B31BD289BC00B30411 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 8D6765B61BD289BC00B30411 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 8D6765B81BD289BC00B30411 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + AB1507161BD297BA00410122 /* weatherListTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = weatherListTableViewController.h; path = ../weatherListTableViewController.h; sourceTree = ""; }; + AB1507171BD297BA00410122 /* weatherListTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = weatherListTableViewController.m; path = ../weatherListTableViewController.m; sourceTree = ""; }; + AB1507191BD297E600410122 /* CoordinateInputViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoordinateInputViewController.h; sourceTree = ""; }; + AB15071A1BD297E600410122 /* CoordinateInputViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CoordinateInputViewController.m; sourceTree = ""; }; + AB15071C1BD2980500410122 /* DetailWeatherViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailWeatherViewController.h; sourceTree = ""; }; + AB15071D1BD2980500410122 /* DetailWeatherViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailWeatherViewController.m; sourceTree = ""; }; + AB15071F1BD2981E00410122 /* APIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIManager.h; sourceTree = ""; }; + AB1507201BD2981E00410122 /* APIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIManager.m; sourceTree = ""; }; + AB1507251BD2C52700410122 /* CustomWeatherTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomWeatherTableViewCell.h; sourceTree = ""; }; + AB1507261BD2C52700410122 /* CustomWeatherTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomWeatherTableViewCell.m; sourceTree = ""; }; + AB1507281BD2CBD700410122 /* DailyWeatherObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DailyWeatherObject.h; sourceTree = ""; }; + AB1507291BD2CBD700410122 /* DailyWeatherObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DailyWeatherObject.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -62,8 +77,18 @@ children = ( 8D6765A71BD289BC00B30411 /* AppDelegate.h */, 8D6765A81BD289BC00B30411 /* AppDelegate.m */, - 8D6765AA1BD289BC00B30411 /* ViewController.h */, - 8D6765AB1BD289BC00B30411 /* ViewController.m */, + AB1507161BD297BA00410122 /* weatherListTableViewController.h */, + AB1507171BD297BA00410122 /* weatherListTableViewController.m */, + AB1507191BD297E600410122 /* CoordinateInputViewController.h */, + AB15071A1BD297E600410122 /* CoordinateInputViewController.m */, + AB15071C1BD2980500410122 /* DetailWeatherViewController.h */, + AB15071D1BD2980500410122 /* DetailWeatherViewController.m */, + AB15071F1BD2981E00410122 /* APIManager.h */, + AB1507201BD2981E00410122 /* APIManager.m */, + AB1507251BD2C52700410122 /* CustomWeatherTableViewCell.h */, + AB1507261BD2C52700410122 /* CustomWeatherTableViewCell.m */, + AB1507281BD2CBD700410122 /* DailyWeatherObject.h */, + AB1507291BD2CBD700410122 /* DailyWeatherObject.m */, 8D6765AD1BD289BC00B30411 /* Main.storyboard */, 8D6765B31BD289BC00B30411 /* Assets.xcassets */, 8D6765B51BD289BC00B30411 /* LaunchScreen.storyboard */, @@ -152,9 +177,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + AB1507181BD297BA00410122 /* weatherListTableViewController.m in Sources */, + AB15071B1BD297E600410122 /* CoordinateInputViewController.m in Sources */, 8D6765B21BD289BC00B30411 /* unit_2_assessment.xcdatamodeld in Sources */, - 8D6765AC1BD289BC00B30411 /* ViewController.m in Sources */, + AB15072A1BD2CBD700410122 /* DailyWeatherObject.m in Sources */, 8D6765A91BD289BC00B30411 /* AppDelegate.m in Sources */, + AB1507211BD2981E00410122 /* APIManager.m in Sources */, + AB1507271BD2C52700410122 /* CustomWeatherTableViewCell.m in Sources */, + AB15071E1BD2980500410122 /* DetailWeatherViewController.m in Sources */, 8D6765A61BD289BC00B30411 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -302,6 +332,7 @@ 8D6765BD1BD289BC00B30411 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ diff --git a/unit-2-assessment/unit-2-assessment/APIManager.h b/unit-2-assessment/unit-2-assessment/APIManager.h new file mode 100644 index 0000000..1a30897 --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/APIManager.h @@ -0,0 +1,18 @@ +// +// APIManager.h +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface APIManager : NSObject + ++ (void)GETRequestWithURL:(NSURL *)URL + completionHandler:(void(^)(NSData *data, NSURLResponse *response, NSError *error))completionBlock; + + + +@end diff --git a/unit-2-assessment/unit-2-assessment/APIManager.m b/unit-2-assessment/unit-2-assessment/APIManager.m new file mode 100644 index 0000000..62f63fb --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/APIManager.m @@ -0,0 +1,30 @@ +// +// APIManager.m +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "APIManager.h" + +@implementation APIManager + ++ (void)GETRequestWithURL:(NSURL *)URL + completionHandler:(void(^)(NSData *data, NSURLResponse *response, NSError *error))completionBlock { + + NSURLSession *session = [NSURLSession sharedSession]; + + NSURLSessionDataTask *task = [session dataTaskWithURL:URL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + + dispatch_async(dispatch_get_main_queue(), ^{ + completionBlock(data, response, error); + }); + }]; + + [task resume]; + +} + + +@end diff --git a/unit-2-assessment/unit-2-assessment/Assets.xcassets/Contents.json b/unit-2-assessment/unit-2-assessment/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/unit-2-assessment/unit-2-assessment/Base.lproj/Main.storyboard b/unit-2-assessment/unit-2-assessment/Base.lproj/Main.storyboard index e627b3b..c9ea046 100644 --- a/unit-2-assessment/unit-2-assessment/Base.lproj/Main.storyboard +++ b/unit-2-assessment/unit-2-assessment/Base.lproj/Main.storyboard @@ -1,26 +1,342 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/unit-2-assessment/unit-2-assessment/CoordinateInputViewController.h b/unit-2-assessment/unit-2-assessment/CoordinateInputViewController.h new file mode 100644 index 0000000..45a4b2c --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/CoordinateInputViewController.h @@ -0,0 +1,27 @@ +// +// CoordinateInputViewController.h +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "weatherListTableViewController.h" +#import "APIManager.h" + + +@interface CoordinateInputViewController : UIViewController +@property (strong, nonatomic) IBOutlet UITextField *latitudeInput; +@property (strong, nonatomic) IBOutlet UITextField *longitudeInput; + + + + +@property (nonatomic) NSString* latitude; +@property (nonatomic) NSString* longitude; + + +@property (nonatomic) NSURL * url; + +@end diff --git a/unit-2-assessment/unit-2-assessment/CoordinateInputViewController.m b/unit-2-assessment/unit-2-assessment/CoordinateInputViewController.m new file mode 100644 index 0000000..4e7ddca --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/CoordinateInputViewController.m @@ -0,0 +1,67 @@ +// +// CoordinateInputViewController.m +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "CoordinateInputViewController.h" + +@interface CoordinateInputViewController () + + +@end + +@implementation CoordinateInputViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +-(void)defineURL{ + + if(self.latitudeInput.text != nil && self.longitudeInput.text != nil){ + self.latitude = [NSString stringWithFormat:@"%@",self.latitudeInput.text]; + self.longitude = [NSString stringWithFormat:@"%@",self.longitudeInput.text]; + } + + + + NSString* forecastIOString = [NSString stringWithFormat: @"https://api.forecast.io/forecast/8040fc5b15adaaafabbe7de9c3ff5458/%@,%@",self.latitude, self.longitude]; + + + self.url = [NSURL URLWithString:forecastIOString]; + + // Do any additional setup after loading the view. +} + + + + + + + + + + #pragma mark - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + [self defineURL]; + + weatherListTableViewController* viewcontroller = segue.destinationViewController; + viewcontroller.forecasturl = self.url; + + } + + @end diff --git a/unit-2-assessment/unit-2-assessment/CustomWeatherTableViewCell.h b/unit-2-assessment/unit-2-assessment/CustomWeatherTableViewCell.h new file mode 100644 index 0000000..6d0d020 --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/CustomWeatherTableViewCell.h @@ -0,0 +1,23 @@ +// +// CustomWeatherTableViewCell.h +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "weatherListTableViewController.h" +#import "DailyWeatherObject.h" +@interface CustomWeatherTableViewCell : UITableViewCell + + +@property (strong, nonatomic) IBOutlet UILabel *dayOfTheWeekLabel; + +@property (strong, nonatomic) IBOutlet UIImageView *weatherPicLabel; + +@property (strong, nonatomic) IBOutlet UILabel *highLowTempLabel; + +@property (nonatomic) DailyWeatherObject* weatherObject; + +@end diff --git a/unit-2-assessment/unit-2-assessment/CustomWeatherTableViewCell.m b/unit-2-assessment/unit-2-assessment/CustomWeatherTableViewCell.m new file mode 100644 index 0000000..87dd6c5 --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/CustomWeatherTableViewCell.m @@ -0,0 +1,23 @@ +// +// CustomWeatherTableViewCell.m +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "CustomWeatherTableViewCell.h" + +@implementation CustomWeatherTableViewCell + +- (void)awakeFromNib { + // Initialization code +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} + +@end diff --git a/unit-2-assessment/unit-2-assessment/DailyWeatherObject.h b/unit-2-assessment/unit-2-assessment/DailyWeatherObject.h new file mode 100644 index 0000000..dff4f4d --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/DailyWeatherObject.h @@ -0,0 +1,21 @@ +// +// DailyWeatherObject.h +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface DailyWeatherObject : NSObject + +@property (nonatomic) NSString* time; //day +@property (nonatomic) NSString* windSpeed; +@property (nonatomic) NSString* humidity; +@property (nonatomic) NSString* summary; +@property (nonatomic) NSString* precipProbability; //chance of precipitation +@property (nonatomic) NSString* temperatureMin; +@property (nonatomic) NSString* temperatureMax; +@property (nonatomic) NSString* weatherPic; +@end diff --git a/unit-2-assessment/unit-2-assessment/DailyWeatherObject.m b/unit-2-assessment/unit-2-assessment/DailyWeatherObject.m new file mode 100644 index 0000000..1a4db6a --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/DailyWeatherObject.m @@ -0,0 +1,13 @@ +// +// DailyWeatherObject.m +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "DailyWeatherObject.h" + +@implementation DailyWeatherObject + +@end diff --git a/unit-2-assessment/unit-2-assessment/DetailWeatherViewController.h b/unit-2-assessment/unit-2-assessment/DetailWeatherViewController.h new file mode 100644 index 0000000..41a27f6 --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/DetailWeatherViewController.h @@ -0,0 +1,25 @@ +// +// DetailWeatherViewController.h +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "APIManager.h" +#import "weatherListTableViewController.h" +#import "DailyWeatherObject.h" + +@interface DetailWeatherViewController : UIViewController + +- (IBAction)backButtonTapped:(id)sender; + +@property (strong, nonatomic) IBOutlet UIImageView *weatherPicImage; +@property (strong, nonatomic) IBOutlet UILabel *chanceOfRainLabel; +@property (strong, nonatomic) IBOutlet UILabel *humidityLabel; +@property (strong, nonatomic) IBOutlet UILabel *windLabel; +@property (nonatomic) DailyWeatherObject* detailWeatherObject; +@property (strong, nonatomic) IBOutlet UITextView *summaryTextView; + +@end diff --git a/unit-2-assessment/unit-2-assessment/DetailWeatherViewController.m b/unit-2-assessment/unit-2-assessment/DetailWeatherViewController.m new file mode 100644 index 0000000..5a9fddf --- /dev/null +++ b/unit-2-assessment/unit-2-assessment/DetailWeatherViewController.m @@ -0,0 +1,57 @@ +// +// DetailWeatherViewController.m +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "DetailWeatherViewController.h" + +@interface DetailWeatherViewController () + +@end + +@implementation DetailWeatherViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + NSLog(@"%@",self.detailWeatherObject.windSpeed); + + self.weatherPicImage.image = [UIImage imageNamed:self.detailWeatherObject.weatherPic]; + self.humidityLabel.text =[NSString stringWithFormat: @"humidity:%@",self.detailWeatherObject.humidity]; + self.windLabel.text = [NSString stringWithFormat:@"windSpeed:%@ mph", self.detailWeatherObject.windSpeed]; + self.chanceOfRainLabel.text =[NSString stringWithFormat: @"Chance of Rain: %@ /100", self.detailWeatherObject.precipProbability]; + self.summaryTextView.text= [NSString stringWithFormat: @"%@", self.detailWeatherObject.summary]; + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + + + +//-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ +// +// +// +//} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +- (IBAction)backButtonTapped:(id)sender { + + [self dismissViewControllerAnimated:NO completion:nil]; +} +@end diff --git a/unit-2-assessment/weatherListTableViewController.h b/unit-2-assessment/weatherListTableViewController.h new file mode 100644 index 0000000..736150a --- /dev/null +++ b/unit-2-assessment/weatherListTableViewController.h @@ -0,0 +1,28 @@ +// +// weatherListTableViewController.h +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "CoordinateInputViewController.h" +#import "APIManager.h" +#import "CustomWeatherTableViewCell.h" +#import "DailyWeatherObject.h" +#import "DetailWeatherViewController.h" +#import "CustomWeatherTableViewCell.h" + +@interface weatherListTableViewController : UITableViewController +@property (nonatomic) NSURL* forecasturl; + + +@property (nonatomic) NSString* summary; +@property (nonatomic) NSString* tempHigh; +@property (nonatomic) NSString* tempLow; + +@property NSMutableArray* weatherObjects; + + +@end diff --git a/unit-2-assessment/weatherListTableViewController.m b/unit-2-assessment/weatherListTableViewController.m new file mode 100644 index 0000000..2444b85 --- /dev/null +++ b/unit-2-assessment/weatherListTableViewController.m @@ -0,0 +1,178 @@ +// +// weatherListTableViewController.m +// unit-2-assessment +// +// Created by Bereket on 10/17/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "weatherListTableViewController.h" + +@interface weatherListTableViewController () + +@end + +@implementation weatherListTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + + + self.weatherObjects = [[NSMutableArray alloc] init]; + + + if(self.forecasturl == nil){ + + NSLog(@"self.forecasturl doesnt have a value yet"); + // Uncomment the following line to preserve selection between presentations. + // self.clearsSelectionOnViewWillAppear = NO; + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem; +} + else{ + NSLog(@"%@", [NSString stringWithFormat:@"%@",self.forecasturl]); + + [self fetchForeCastData]; + } + + + +} + +-(void)fetchForeCastData{ + [APIManager GETRequestWithURL:self.forecasturl completionHandler:^(NSData* data, NSURLResponse* response, NSError* error){ + + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + + NSArray *results = [[json objectForKey:@"daily"] objectForKey:@"data"]; + + NSLog(@"%@", results); + + for (NSDictionary* result in results) { + DailyWeatherObject* weatherObject = [[DailyWeatherObject alloc] init]; + + weatherObject.time = [NSString stringWithFormat:@"%@",[result objectForKey:@"time"]]; + weatherObject.windSpeed = [NSString stringWithFormat:@"%@",[result objectForKey:@"windSpeed"]]; + weatherObject.humidity = [NSString stringWithFormat:@"%@",[result objectForKey:@"humidity"]]; + weatherObject.summary = [result objectForKey:@"summary"]; + weatherObject.precipProbability = [NSString stringWithFormat:@"%@",[result objectForKey:@"precipProbability"]]; + weatherObject.temperatureMax = [NSString stringWithFormat:@"%@",[result objectForKey:@"temperatureMax"]]; + weatherObject.temperatureMin = [NSString stringWithFormat:@"%@",[result objectForKey:@"temperatureMin"]]; + weatherObject.weatherPic = [NSString stringWithFormat:@"%@", [result objectForKey:@"icon"]]; + + + [self.weatherObjects addObject:weatherObject]; + + NSLog(@"%lu", (unsigned long)self.weatherObjects.count); + + } + + + [self.tableView reloadData]; + + + }]; + +} + + + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.weatherObjects.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + CustomWeatherTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WeatherDataCellIdentifier" forIndexPath:indexPath]; + + cell.weatherObject = self.weatherObjects[indexPath.row]; + cell.dayOfTheWeekLabel.text= cell.weatherObject.time; + + cell.highLowTempLabel.text = [NSString stringWithFormat:@"%@/%@", cell.weatherObject.temperatureMax, cell.weatherObject.temperatureMin]; + + cell.weatherPicLabel.image = [UIImage imageNamed:cell.weatherObject.weatherPic]; + + + return cell; +} + + +/* +// Override to support conditional editing of the table view. +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { + // Return NO if you do not want the specified item to be editable. + return YES; +} +*/ + +/* +// Override to support editing the table view. +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { + if (editingStyle == UITableViewCellEditingStyleDelete) { + // Delete the row from the data source + [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; + } else if (editingStyle == UITableViewCellEditingStyleInsert) { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } +} +*/ + +/* +// Override to support rearranging the table view. +- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { +} +*/ + +/* +// Override to support conditional rearranging of the table view. +- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { + // Return NO if you do not want the item to be re-orderable. + return YES; +} +*/ + + + + +#pragma mark - Navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + if (self.forecasturl == nil) { + NSLog(@"try not to crash"); + } + + + else{ + + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + + UINavigationController* navController= segue.destinationViewController; + DetailWeatherViewController* viewController = navController.viewControllers[0]; + + + NSLog(@"Are we there yet?"); + + DailyWeatherObject* weatherObject= self.weatherObjects[indexPath.row]; + + viewController.detailWeatherObject = weatherObject; + + + + + } + + + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} + + +@end