diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa9413e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +jakeswedenburg.xcuserdatad +.DS_Store diff --git a/Stormy.xcodeproj/project.pbxproj b/Stormy.xcodeproj/project.pbxproj index ee67973..91e7e5d 100755 --- a/Stormy.xcodeproj/project.pbxproj +++ b/Stormy.xcodeproj/project.pbxproj @@ -194,9 +194,11 @@ TargetAttributes = { 218C583519D86BA20054DBD0 = { CreatedOnToolsVersion = 6.0.1; + LastSwiftMigration = 0810; }; 218C584A19D86BA30054DBD0 = { CreatedOnToolsVersion = 6.0.1; + LastSwiftMigration = 0810; TestTargetID = 218C583519D86BA20054DBD0; }; }; @@ -380,10 +382,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Stormy/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 1; }; name = Debug; @@ -394,10 +398,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Stormy/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 1; }; name = Release; @@ -417,6 +423,7 @@ INFOPLIST_FILE = StormyTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Stormy.app/Stormy"; }; name = Debug; @@ -432,6 +439,7 @@ INFOPLIST_FILE = StormyTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Stormy.app/Stormy"; }; name = Release; diff --git a/Stormy/AppDelegate.swift b/Stormy/AppDelegate.swift index aa42e32..f137222 100755 --- a/Stormy/AppDelegate.swift +++ b/Stormy/AppDelegate.swift @@ -11,11 +11,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { - application.setStatusBarHidden(true, withAnimation: .None) + application.setStatusBarHidden(true, with: .none) - application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [UIUserNotificationType.Sound, UIUserNotificationType.Alert, UIUserNotificationType.Badge], categories: nil)) + application.registerUserNotificationSettings(UIUserNotificationSettings(types: [UIUserNotificationType.sound, UIUserNotificationType.alert, UIUserNotificationType.badge], categories: nil)) //sleep(2); @@ -23,25 +23,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/Stormy/Current.swift b/Stormy/Current.swift index 4e21162..665e87f 100755 --- a/Stormy/Current.swift +++ b/Stormy/Current.swift @@ -18,7 +18,7 @@ struct Current { var windSpeed: Double - init (weatherDictionary: NSDictionary) { + init (weatherDictionary: [String: Any]) { let currentWeather = weatherDictionary["currently"] as! NSDictionary temperature = currentWeather["temperature"] as! Int @@ -35,15 +35,15 @@ struct Current { //Date formatter -func dateStringFromUnixtime(unixTime: Int) -> String { +func dateStringFromUnixtime(_ unixTime: Int) -> String { - let timeInSeconds = NSTimeInterval(unixTime) - let weatherDate = NSDate(timeIntervalSince1970: timeInSeconds) + let timeInSeconds = TimeInterval(unixTime) + let weatherDate = Date(timeIntervalSince1970: timeInSeconds) - let dateFormatter = NSDateFormatter() - dateFormatter.timeStyle = .MediumStyle + let dateFormatter = DateFormatter() + dateFormatter.timeStyle = .medium - return dateFormatter.stringFromDate(weatherDate) + return dateFormatter.string(from: weatherDate) } @@ -51,7 +51,7 @@ func dateStringFromUnixtime(unixTime: Int) -> String { //Images -func weatherIconFromString(stringIcon: String) -> UIImage { +func weatherIconFromString(_ stringIcon: String) -> UIImage { var imageName: String @@ -85,7 +85,7 @@ func weatherIconFromString(stringIcon: String) -> UIImage { } -func Fahrenheit2Celsius(f: Int) -> Int { +func Fahrenheit2Celsius(_ f: Int) -> Int { return Int((Double(f)-32.0) / 1.8) } diff --git a/Stormy/InfoTabViewController.swift b/Stormy/InfoTabViewController.swift index 2c28bfd..547fd32 100755 --- a/Stormy/InfoTabViewController.swift +++ b/Stormy/InfoTabViewController.swift @@ -29,24 +29,24 @@ class InfoTabViewController: UIViewController { func infoAnimation() { - self.thermometer.transform = CGAffineTransformMakeTranslation(0, 1000) - self.projectName.transform = CGAffineTransformMakeTranslation(0, 100) - self.forecast.transform = CGAffineTransformMakeTranslation(0, 100) + self.thermometer.transform = CGAffineTransform(translationX: 0, y: 1000) + self.projectName.transform = CGAffineTransform(translationX: 0, y: 100) + self.forecast.transform = CGAffineTransform(translationX: 0, y: 100) springWithDelay(0.9, delay: 0.50, animations: { - self.thermometer.transform = CGAffineTransformMakeTranslation(0, 0) + self.thermometer.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.50, animations: { - self.projectName.transform = CGAffineTransformMakeTranslation(0, 0) + self.projectName.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.50, animations: { - self.forecast.transform = CGAffineTransformMakeTranslation(0, 0) + self.forecast.transform = CGAffineTransform(translationX: 0, y: 0) }) } - @IBAction func backButtonPressed(sender: AnyObject) { + @IBAction func backButtonPressed(_ sender: AnyObject) { } diff --git a/Stormy/SpringAnimation.swift b/Stormy/SpringAnimation.swift index 3ffcb80..227109d 100755 --- a/Stormy/SpringAnimation.swift +++ b/Stormy/SpringAnimation.swift @@ -13,9 +13,9 @@ var delay = 0.0 var damping = 0.7 var velocity = 0.7 -func spring(duration: NSTimeInterval, animations: (() -> Void)!) { +func spring(_ duration: TimeInterval, animations: (() -> Void)!) { - UIView.animateWithDuration(duration, delay: delay, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [], animations: { + UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [], animations: { animations() @@ -24,9 +24,9 @@ func spring(duration: NSTimeInterval, animations: (() -> Void)!) { }) } -func springWithDelay(duration: NSTimeInterval, delay: NSTimeInterval, animations: (() -> Void)!) { +func springWithDelay(_ duration: TimeInterval, delay: TimeInterval, animations: (() -> Void)!) { - UIView.animateWithDuration(duration, delay: delay, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: [], animations: { + UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: [], animations: { animations() @@ -35,17 +35,17 @@ func springWithDelay(duration: NSTimeInterval, delay: NSTimeInterval, animations }) } -func slideUp(duration: NSTimeInterval, animations: (() -> Void)!) { - UIView.animateWithDuration(duration, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: [], animations: { +func slideUp(_ duration: TimeInterval, animations: (() -> Void)!) { + UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: [], animations: { animations() }, completion: nil) } -func springWithCompletion(duration: NSTimeInterval, animations: (() -> Void)!, completion: ((Bool) -> Void)!) { +func springWithCompletion(_ duration: TimeInterval, animations: (() -> Void)!, completion: ((Bool) -> Void)!) { - UIView.animateWithDuration(duration, delay: delay, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [], animations: { + UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [], animations: { animations() @@ -54,47 +54,47 @@ func springWithCompletion(duration: NSTimeInterval, animations: (() -> Void)!, c }) } -func springScaleFrom (view: UIView, x: CGFloat, y: CGFloat, scaleX: CGFloat, scaleY: CGFloat) { - let translation = CGAffineTransformMakeTranslation(x, y) - let scale = CGAffineTransformMakeScale(scaleX, scaleY) - view.transform = CGAffineTransformConcat(translation, scale) +func springScaleFrom (_ view: UIView, x: CGFloat, y: CGFloat, scaleX: CGFloat, scaleY: CGFloat) { + let translation = CGAffineTransform(translationX: x, y: y) + let scale = CGAffineTransform(scaleX: scaleX, y: scaleY) + view.transform = translation.concatenating(scale) - UIView.animateWithDuration(0.7, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [], animations: { + UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [], animations: { - let translation = CGAffineTransformMakeTranslation(0, 0) - let scale = CGAffineTransformMakeScale(1, 1) - view.transform = CGAffineTransformConcat(translation, scale) + let translation = CGAffineTransform(translationX: 0, y: 0) + let scale = CGAffineTransform(scaleX: 1, y: 1) + view.transform = translation.concatenating(scale) }, completion: nil) } -func springScaleTo (view: UIView, x: CGFloat, y: CGFloat, scaleX: CGFloat, scaleY: CGFloat) { - let translation = CGAffineTransformMakeTranslation(0, 0) - let scale = CGAffineTransformMakeScale(1, 1) - view.transform = CGAffineTransformConcat(translation, scale) +func springScaleTo (_ view: UIView, x: CGFloat, y: CGFloat, scaleX: CGFloat, scaleY: CGFloat) { + let translation = CGAffineTransform(translationX: 0, y: 0) + let scale = CGAffineTransform(scaleX: 1, y: 1) + view.transform = translation.concatenating(scale) - UIView.animateWithDuration(duration, delay: delay, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [], animations: { + UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [], animations: { - let translation = CGAffineTransformMakeTranslation(x, y) - let scale = CGAffineTransformMakeScale(scaleX, scaleY) - view.transform = CGAffineTransformConcat(translation, scale) + let translation = CGAffineTransform(translationX: x, y: y) + let scale = CGAffineTransform(scaleX: scaleX, y: scaleY) + view.transform = translation.concatenating(scale) }, completion: nil) } -func popoverTopRight(view: UIView) { - view.hidden = false - let translate = CGAffineTransformMakeTranslation(200, -200) - let scale = CGAffineTransformMakeScale(0.3, 0.3) +func popoverTopRight(_ view: UIView) { + view.isHidden = false + let translate = CGAffineTransform(translationX: 200, y: -200) + let scale = CGAffineTransform(scaleX: 0.3, y: 0.3) view.alpha = 0 - view.transform = CGAffineTransformConcat(translate, scale) + view.transform = translate.concatenating(scale) - UIView.animateWithDuration(0.6, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.8, options: [], animations: { + UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.8, options: [], animations: { - let translate = CGAffineTransformMakeTranslation(0, 0) - let scale = CGAffineTransformMakeScale(1, 1) - view.transform = CGAffineTransformConcat(translate, scale) + let translate = CGAffineTransform(translationX: 0, y: 0) + let scale = CGAffineTransform(scaleX: 1, y: 1) + view.transform = translate.concatenating(scale) view.alpha = 1 }, completion: nil) -} \ No newline at end of file +} diff --git a/Stormy/ViewController.swift b/Stormy/ViewController.swift index bc0fce4..7e1e8f0 100755 --- a/Stormy/ViewController.swift +++ b/Stormy/ViewController.swift @@ -72,9 +72,9 @@ class ViewController: UIViewController,CLLocationManagerDelegate { var locationFixAchieved : Bool = false var locationStatus : NSString = "Not Started" var locationManager: CLLocationManager! - var userLocation : String! - var userLatitude : Double! - var userLongitude : Double! +// var userLocation : String! + var userLatitude : Double? + var userLongitude : Double? var userTemperatureCelsius : Bool! private let apiKey = "YOUR API KEY" // https://developer.forecast.io @@ -88,12 +88,12 @@ class ViewController: UIViewController,CLLocationManagerDelegate { // Do any additional setup after loading the view, typically from a nib. // Get user preference - let defaults: NSUserDefaults = NSUserDefaults.standardUserDefaults() - userTemperatureCelsius = defaults.boolForKey("celsius") + let defaults: UserDefaults = UserDefaults.standard + userTemperatureCelsius = defaults.bool(forKey: "celsius") print("defaults: celsius = \(userTemperatureCelsius)"); - swipeRec.addTarget(self, action: "swipedView") - swipeRec.direction = UISwipeGestureRecognizerDirection.Down + swipeRec.addTarget(self, action: #selector(ViewController.swipedView)) + swipeRec.direction = UISwipeGestureRecognizerDirection.down swipeView.addGestureRecognizer(swipeRec) refresh() @@ -126,7 +126,7 @@ class ViewController: UIViewController,CLLocationManagerDelegate { - func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error)->Void in let pm = placemarks![0] @@ -135,9 +135,9 @@ class ViewController: UIViewController,CLLocationManagerDelegate { if (locationFixAchieved == false) { locationFixAchieved = true - var locationArray = locations as NSArray - var locationObj = locationArray.lastObject as! CLLocation - var coord = locationObj.coordinate + let locationArray = locations as NSArray + let locationObj = locationArray.lastObject as! CLLocation + let coord = locationObj.coordinate self.userLatitude = coord.latitude self.userLongitude = coord.longitude @@ -147,39 +147,39 @@ class ViewController: UIViewController,CLLocationManagerDelegate { } } - func displayLocationInfo(placemark: CLPlacemark?) { + func displayLocationInfo(_ placemark: CLPlacemark?) { if let containsPlacemark = placemark { //stop updating location to save battery life locationManager.stopUpdatingLocation() - let locality = (containsPlacemark.locality != nil) ? containsPlacemark.locality : "" - let postalCode = (containsPlacemark.postalCode != nil) ? containsPlacemark.postalCode : "" - let administrativeArea = (containsPlacemark.administrativeArea != nil) ? containsPlacemark.administrativeArea : "" - let country = (containsPlacemark.country != nil) ? containsPlacemark.country : "" - //println(locality) - //println(postalCode) - //println(administrativeArea) - //println(country) + let locality = containsPlacemark.locality ?? "" + let postalCode = containsPlacemark.postalCode ?? "" + let administrativeArea = containsPlacemark.administrativeArea ?? "" + let country = containsPlacemark.country ?? "" + //print(locality) + //print(postalCode) + //print(administrativeArea) + //print(country) self.userLocationLabel.text = "\(locality), \(administrativeArea)" } } - func locationManager(manager: CLLocationManager, - didChangeAuthorizationStatus status: CLAuthorizationStatus) { + func locationManager(_ manager: CLLocationManager, + didChangeAuthorization status: CLAuthorizationStatus) { var shouldIAllow = false switch status { - case CLAuthorizationStatus.Restricted: + case CLAuthorizationStatus.restricted: locationStatus = "Restricted Access to location" - case CLAuthorizationStatus.Denied: + case CLAuthorizationStatus.denied: locationStatus = "User denied access to location" - case CLAuthorizationStatus.NotDetermined: + case CLAuthorizationStatus.notDetermined: locationStatus = "Status not determined" default: locationStatus = "Allowed to location Access" shouldIAllow = true } - NSNotificationCenter.defaultCenter().postNotificationName("LabelHasbeenUpdated", object: nil) + NotificationCenter.default.post(name: Notification.Name(rawValue: "LabelHasbeenUpdated"), object: nil) if (shouldIAllow == true) { NSLog("Location to Allowed") // Start location services @@ -193,26 +193,27 @@ class ViewController: UIViewController,CLLocationManagerDelegate { //WEATHER func getCurrentWeatherData() -> Void { + guard let userLatitude = self.userLatitude, let userLongitude = self.userLongitude else { return } - userLocation = "\(userLatitude),\(userLongitude)" - - let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/") - let forecastURL = NSURL(string: "\(userLocation)", relativeToURL:baseURL) + let userLocation = "\(userLatitude),\(userLongitude)" + let urlString = "https://api.forecast.io/forecast/\(apiKey)/\(userLocation)" + let forecastURL = URL(string: urlString) //72.371224,-41.382676 GreenLand (Cold Place!) //\(userLocation) (YOUR LOCATION!) //println(userLocation) - let sharedSession = NSURLSession.sharedSession() + let sharedSession = URLSession.shared + - let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: { (location: NSURL?, response: NSURLResponse?, error: NSError?) -> Void in + let downloadTask: URLSessionDownloadTask = sharedSession.downloadTask(with: forecastURL!, completionHandler: { (location: URL?, response: URLResponse?, error: Error?) -> Void in if (error == nil) { - let dataObject = NSData(contentsOfURL: location!) - let weatherDictionary: NSDictionary = (try! NSJSONSerialization.JSONObjectWithData(dataObject!, options: [])) as! NSDictionary + let dataObject = try? Data(contentsOf: location!) + let weatherDictionary = (try! JSONSerialization.jsonObject(with: dataObject!, options: [])) as! [String: Any] let currentWeather = Current(weatherDictionary: weatherDictionary) let weeklyWeather = Weekly(weatherDictionary: weatherDictionary) @@ -224,7 +225,7 @@ class ViewController: UIViewController,CLLocationManagerDelegate { //println(currentWeather.currentTime!) print(weatherDictionary) - dispatch_async(dispatch_get_main_queue(), { () -> Void in + DispatchQueue.main.async(execute: { () -> Void in //Current outlook // self.userTemperatureCelsius = true @@ -258,8 +259,8 @@ class ViewController: UIViewController,CLLocationManagerDelegate { var localNotification:UILocalNotification = UILocalNotification() localNotification.alertAction = "Project RainMan" localNotification.alertBody = "Don't forget your umbrella today!" - localNotification.fireDate = NSDate(timeIntervalSinceNow: 8) - UIApplication.sharedApplication().scheduleLocalNotification(localNotification) + localNotification.fireDate = Date(timeIntervalSinceNow: 8) + UIApplication.shared.scheduleLocalNotification(localNotification) } @@ -268,8 +269,8 @@ class ViewController: UIViewController,CLLocationManagerDelegate { var localNotification:UILocalNotification = UILocalNotification() localNotification.alertAction = "Project RainMan" localNotification.alertBody = "It's going to be windy today!" - localNotification.fireDate = NSDate(timeIntervalSinceNow: 8) - UIApplication.sharedApplication().scheduleLocalNotification(localNotification) + localNotification.fireDate = Date(timeIntervalSinceNow: 8) + UIApplication.shared.scheduleLocalNotification(localNotification) } @@ -278,8 +279,8 @@ class ViewController: UIViewController,CLLocationManagerDelegate { var localNotification:UILocalNotification = UILocalNotification() localNotification.alertAction = "Project RainMan" localNotification.alertBody = "It's going to be Hot today!" - localNotification.fireDate = NSDate(timeIntervalSinceNow: 8) - UIApplication.sharedApplication().scheduleLocalNotification(localNotification) + localNotification.fireDate = Date(timeIntervalSinceNow: 8) + UIApplication.shared.scheduleLocalNotification(localNotification) } @@ -354,23 +355,23 @@ class ViewController: UIViewController,CLLocationManagerDelegate { } else { - let networkIssueController = UIAlertController(title: "NO API KEY", message: "Hello! Looks like you forgot to add the API KEY on line 79", preferredStyle: .Alert) - let okButton = UIAlertAction(title: "OK", style: .Default, handler: nil) + let networkIssueController = UIAlertController(title: "NO API KEY", message: "Hello! Looks like you forgot to add the API KEY on line 79", preferredStyle: .alert) + let okButton = UIAlertAction(title: "OK", style: .default, handler: nil) networkIssueController.addAction(okButton) - let cancelButton = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) + let cancelButton = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) networkIssueController.addAction(cancelButton) - self.presentViewController(networkIssueController, animated: true, completion: nil) + self.present(networkIssueController, animated: true, completion: nil) - dispatch_async(dispatch_get_main_queue(), { () -> Void in + DispatchQueue.main.async(execute: { () -> Void in }) } - }) + } as! (URL?, URLResponse?, Error?) -> Void) - downloadTask.resume() + downloadTask.resume() } @@ -409,7 +410,7 @@ class ViewController: UIViewController,CLLocationManagerDelegate { self.weeklyForcastAnimation() - UIView.animateWithDuration(1.5, animations: { + UIView.animate(withDuration: 1.5, animations: { self.temperatureLabel.alpha = 1.0 self.heatIndex.alpha = 1.0 self.dayOneImage.alpha = 1.0 @@ -446,38 +447,38 @@ class ViewController: UIViewController,CLLocationManagerDelegate { //DAILY - self.dayZeroTemperatureLowLabel.transform = CGAffineTransformMakeTranslation(-300, 0) - self.dayZeroTemperatureHighLabel.transform = CGAffineTransformMakeTranslation(300, 0) - self.windBag.transform = CGAffineTransformMakeTranslation(0, -600) - self.umbrella.transform = CGAffineTransformMakeTranslation(0, -600) - self.rainDrop.transform = CGAffineTransformMakeTranslation(0, -600) - self.iconView.transform = CGAffineTransformMakeTranslation(-200, 0) - self.temperatureLabel.transform = CGAffineTransformMakeTranslation(300, 0) - self.summaryLabel.transform = CGAffineTransformMakeTranslation(0, -200) - self.heatIndex.transform = CGAffineTransformMakeTranslation(-350, 0) + self.dayZeroTemperatureLowLabel.transform = CGAffineTransform(translationX: -300, y: 0) + self.dayZeroTemperatureHighLabel.transform = CGAffineTransform(translationX: 300, y: 0) + self.windBag.transform = CGAffineTransform(translationX: 0, y: -600) + self.umbrella.transform = CGAffineTransform(translationX: 0, y: -600) + self.rainDrop.transform = CGAffineTransform(translationX: 0, y: -600) + self.iconView.transform = CGAffineTransform(translationX: -200, y: 0) + self.temperatureLabel.transform = CGAffineTransform(translationX: 300, y: 0) + self.summaryLabel.transform = CGAffineTransform(translationX: 0, y: -200) + self.heatIndex.transform = CGAffineTransform(translationX: -350, y: 0) //self.currentTimeLabel.transform = CGAffineTransformMakeTranslation(350,0) - self.userLocationLabel.transform = CGAffineTransformMakeTranslation(350, 0) - self.degreeButton.transform = CGAffineTransformMakeTranslation(350,0) - self.windUILabel.transform = CGAffineTransformMakeTranslation(-350,0) - self.humidityUILabel.transform = CGAffineTransformMakeTranslation(350,0) - self.degreeButton.transform = CGAffineTransformMakeTranslation(350, 0) + self.userLocationLabel.transform = CGAffineTransform(translationX: 350, y: 0) + self.degreeButton.transform = CGAffineTransform(translationX: 350,y: 0) + self.windUILabel.transform = CGAffineTransform(translationX: -350,y: 0) + self.humidityUILabel.transform = CGAffineTransform(translationX: 350,y: 0) + self.degreeButton.transform = CGAffineTransform(translationX: 350, y: 0) //WEEKLY - self.dayOneImage.transform = CGAffineTransformMakeTranslation(0, 100) - self.dayTwoImage.transform = CGAffineTransformMakeTranslation(0, 100) - self.dayThreeImage.transform = CGAffineTransformMakeTranslation(0, 100) - self.dayFourImage.transform = CGAffineTransformMakeTranslation(0, 100) - self.dayFiveImage.transform = CGAffineTransformMakeTranslation(0, 100) - self.daySixImage.transform = CGAffineTransformMakeTranslation(0, 100) + self.dayOneImage.transform = CGAffineTransform(translationX: 0, y: 100) + self.dayTwoImage.transform = CGAffineTransform(translationX: 0, y: 100) + self.dayThreeImage.transform = CGAffineTransform(translationX: 0, y: 100) + self.dayFourImage.transform = CGAffineTransform(translationX: 0, y: 100) + self.dayFiveImage.transform = CGAffineTransform(translationX: 0, y: 100) + self.daySixImage.transform = CGAffineTransform(translationX: 0, y: 100) //DAILY SPRING ACTION springWithDelay(0.9, delay: 0.45, animations: { - self.userLocationLabel.transform = CGAffineTransformMakeTranslation(0, 0) + self.userLocationLabel.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.60, animations: { - self.degreeButton.transform = CGAffineTransformMakeTranslation(0, 0) + self.degreeButton.transform = CGAffineTransform(translationX: 0, y: 0) }) //springWithDelay(0.9, 0.45, { @@ -485,82 +486,82 @@ class ViewController: UIViewController,CLLocationManagerDelegate { //}) springWithDelay(0.9, delay: 0.25, animations: { - self.windBag.transform = CGAffineTransformMakeTranslation(0, 0) + self.windBag.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.35, animations: { - self.umbrella.transform = CGAffineTransformMakeTranslation(0, 0) + self.umbrella.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.rainDrop.transform = CGAffineTransformMakeTranslation(0, 0) + self.rainDrop.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.iconView.transform = CGAffineTransformMakeTranslation(0, 0) + self.iconView.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.temperatureLabel.transform = CGAffineTransformMakeTranslation(0, 0) + self.temperatureLabel.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.60, animations: { - self.summaryLabel.transform = CGAffineTransformMakeTranslation(0, 0) + self.summaryLabel.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.heatIndex.transform = CGAffineTransformMakeTranslation(0, 0) + self.heatIndex.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.dayZeroTemperatureLowLabel.transform = CGAffineTransformMakeTranslation(0, 0) + self.dayZeroTemperatureLowLabel.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.dayZeroTemperatureHighLabel.transform = CGAffineTransformMakeTranslation(0, 0) + self.dayZeroTemperatureHighLabel.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.userLocationLabel.transform = CGAffineTransformMakeTranslation(0, 0) + self.userLocationLabel.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.windUILabel.transform = CGAffineTransformMakeTranslation(0, 0) + self.windUILabel.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.humidityUILabel.transform = CGAffineTransformMakeTranslation(0, 0) + self.humidityUILabel.transform = CGAffineTransform(translationX: 0, y: 0) }) //WEEKLY FORCAST SPRING ACTION springWithDelay(0.9, delay: 0.25, animations: { - self.dayOneImage.transform = CGAffineTransformMakeTranslation(0, 0) + self.dayOneImage.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.35, animations: { - self.dayTwoImage.transform = CGAffineTransformMakeTranslation(0, 0) + self.dayTwoImage.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.45, animations: { - self.dayThreeImage.transform = CGAffineTransformMakeTranslation(0, 0) + self.dayThreeImage.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.55, animations: { - self.dayFourImage.transform = CGAffineTransformMakeTranslation(0, 0) + self.dayFourImage.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.65, animations: { - self.dayFiveImage.transform = CGAffineTransformMakeTranslation(0, 0) + self.dayFiveImage.transform = CGAffineTransform(translationX: 0, y: 0) }) springWithDelay(0.9, delay: 0.75, animations: { - self.daySixImage.transform = CGAffineTransformMakeTranslation(0, 0) + self.daySixImage.transform = CGAffineTransform(translationX: 0, y: 0) }) } - @IBAction func degreeButtonPressed(sender: AnyObject) { + @IBAction func degreeButtonPressed(_ sender: AnyObject) { print("TemperatureMode \(userTemperatureCelsius)"); @@ -572,12 +573,12 @@ class ViewController: UIViewController,CLLocationManagerDelegate { func swooshsound() { - var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("swoosh", ofType: "wav")!) + let alertSound = URL(fileURLWithPath: Bundle.main.path(forResource: "swoosh", ofType: "wav")!) print(alertSound) var error:NSError? do { - audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound) + audioPlayer = try AVAudioPlayer(contentsOf: alertSound) } catch var error1 as NSError { error = error1 @@ -591,10 +592,10 @@ class ViewController: UIViewController,CLLocationManagerDelegate { - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "infotab"{ - let _ = segue.destinationViewController as! InfoTabViewController + let _ = segue.destination as! InfoTabViewController } diff --git a/Stormy/WeatherAlerts.swift b/Stormy/WeatherAlerts.swift index b6d88e9..040c66f 100755 --- a/Stormy/WeatherAlerts.swift +++ b/Stormy/WeatherAlerts.swift @@ -10,9 +10,9 @@ struct WeatherAlerts { var userAlert: String - init (weatherDictionary: NSDictionary) { + init (weatherDictionary: [String: Any]) { - if let weatheralerts = (weatherDictionary["alerts"] as! NSArray!) { + if let weatheralerts = weatherDictionary["alerts"] as? [[String: Any]] { userAlert = weatheralerts[0]["title"] as! String diff --git a/Stormy/Weekly.swift b/Stormy/Weekly.swift index 8408288..a75c9b4 100755 --- a/Stormy/Weekly.swift +++ b/Stormy/Weekly.swift @@ -42,11 +42,14 @@ struct Weekly { var daySixIcon: UIImage - init (weatherDictionary: NSDictionary) { + init (weatherDictionary: [String : Any]) { + + + let weeklyWeather = weatherDictionary["daily"] as! [String: Any] + + let weeklyForcast = weeklyWeather["data"] as! [[String: Any]] - let weeklyWeather = weatherDictionary["daily"] as! NSDictionary - let weeklyForcast = weeklyWeather["data"] as! NSArray //DAY ZERO dayZeroTemperatureMax = weeklyForcast[0]["temperatureMax"] as! Int @@ -105,16 +108,16 @@ struct Weekly { } -func weeekDateStringFromUnixtime(unixTime: Int) -> String { +func weeekDateStringFromUnixtime(_ unixTime: Int) -> String { - let timeInSeconds = NSTimeInterval(unixTime) - let weatherDate = NSDate(timeIntervalSince1970: timeInSeconds) + let timeInSeconds = TimeInterval(unixTime) + let weatherDate = Date(timeIntervalSince1970: timeInSeconds) - let dateFormatter = NSDateFormatter() + let dateFormatter = DateFormatter() //dateFormatter.timeStyle = .MediumStyle dateFormatter.dateFormat = "EEE" - return dateFormatter.stringFromDate(weatherDate) + return dateFormatter.string(from: weatherDate) } diff --git a/StormyTests/StormyTests.swift b/StormyTests/StormyTests.swift index dc49e8a..3bb99fc 100755 --- a/StormyTests/StormyTests.swift +++ b/StormyTests/StormyTests.swift @@ -28,7 +28,7 @@ class StormyTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock() { + self.measure() { // Put the code you want to measure the time of here. } }