diff --git a/Algorithms/TwoSum.playground/Contents.swift b/Algorithms/TwoSum.playground/Contents.swift index 30cc77a..052424d 100644 --- a/Algorithms/TwoSum.playground/Contents.swift +++ b/Algorithms/TwoSum.playground/Contents.swift @@ -15,7 +15,9 @@ let integers: [Int] = [2, 5, 4, 12, 7] */ func findTarget(_ target: Int, in array: [Int]) -> [Array.Index] { // Ваша реализация - + + + return [0, 1] } diff --git a/SwiftStyle/Rainy/Rainy.xcodeproj/project.pbxproj b/SwiftStyle/Rainy/Rainy.xcodeproj/project.pbxproj index cf71440..604efaa 100644 --- a/SwiftStyle/Rainy/Rainy.xcodeproj/project.pbxproj +++ b/SwiftStyle/Rainy/Rainy.xcodeproj/project.pbxproj @@ -146,7 +146,7 @@ TargetAttributes = { 7B11FC391DB53A6900FA6122 = { CreatedOnToolsVersion = 8.0; - DevelopmentTeam = KH2KDZEEE3; + DevelopmentTeam = DJ22U4RTFT; LastSwiftMigration = 0900; ProvisioningStyle = Automatic; }; @@ -387,7 +387,7 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = KH2KDZEEE3; + DEVELOPMENT_TEAM = DJ22U4RTFT; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/build/Debug-iphoneos/SwiftOpenWeatherMapAPI", @@ -408,7 +408,7 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = KH2KDZEEE3; + DEVELOPMENT_TEAM = DJ22U4RTFT; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/build/Debug-iphoneos/SwiftOpenWeatherMapAPI", diff --git a/SwiftStyle/Rainy/Rainy/AppDelegate.swift b/SwiftStyle/Rainy/Rainy/AppDelegate.swift index 9acb4d2..f1b35e4 100644 --- a/SwiftStyle/Rainy/Rainy/AppDelegate.swift +++ b/SwiftStyle/Rainy/Rainy/AppDelegate.swift @@ -1,52 +1,9 @@ -// -// AppDelegate.swift -// Rainy -// -// Created by Kirill Averyanov on 17/10/16. -// Copyright © 2016 Kirill Averyanov. All rights reserved. -// - import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { - - var window: UIWindow? - - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { - // Override point for customization after application launch. - return true - } - - 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 invalidate graphics rendering callbacks. Games should use this method to pause the game. - } - - 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) { - // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. - } - - 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) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - - -} - - - - - + var window: UIWindow? + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + return true + } +} \ No newline at end of file diff --git a/SwiftStyle/Rainy/Rainy/CurrentWeatherViewController.swift b/SwiftStyle/Rainy/Rainy/CurrentWeatherViewController.swift index 89abfb3..515cda3 100644 --- a/SwiftStyle/Rainy/Rainy/CurrentWeatherViewController.swift +++ b/SwiftStyle/Rainy/Rainy/CurrentWeatherViewController.swift @@ -1,168 +1,152 @@ -// -// FirstViewController.swift -// Rainy -// -// Created by Kirill Averyanov on 17/10/16. -// Copyright © 2016 Kirill Averyanov. All rights reserved. -// - import UIKit import CoreLocation import Alamofire import SwiftyJSON - - -struct coords{ - var lat: Double = 0 - var lon: Double = 0 +struct coords { + var lat: Double = 0 + var lon: Double = 0 } class CurrentWeatherViewController: UIViewController, CLLocationManagerDelegate { - @IBOutlet weak var temperatureLabel: UILabel! - @IBOutlet weak var timeLabel: UILabel! - @IBOutlet weak var stateLabel: UILabel! - @IBOutlet weak var windLabel: UILabel! - @IBOutlet weak var cityNameLabel: UILabel! - @IBOutlet weak var imageWeather: UIImageView! - - private var locationManager: CLLocationManager! - // private let constrain: Constants = Constants() - private var currentForecast: WeatherForecast? { - didSet{ - reloadUI() - } + @IBOutlet weak var temperatureLabel: UILabel! + @IBOutlet weak var timeLabel: UILabel! + @IBOutlet weak var stateLabel: UILabel! + @IBOutlet weak var windLabel: UILabel! + @IBOutlet weak var cityNameLabel: UILabel! + @IBOutlet weak var imageWeather: UIImageView! + + private var locationManager: CLLocationManager! + private var currentForecast: WeatherForecast? { + didSet{ + reloadUI() + } + } + + private let photoResources: [String: UIImage] = [ + "01d":#imageLiteral(resourceName: "sunny"), + "01n":#imageLiteral(resourceName: "moon"), + "02d":#imageLiteral(resourceName: "sunny_clouds"), + "02n":#imageLiteral(resourceName: "moodCloud"), + "03d":#imageLiteral(resourceName: "clouds"), + "03n":#imageLiteral(resourceName: "clouds"), + "04d":#imageLiteral(resourceName: "clouds"), + "04n":#imageLiteral(resourceName: "clouds"), + "09d":#imageLiteral(resourceName: "cloud_rain"), + "09n":#imageLiteral(resourceName: "cloud_rain"), + "10d":#imageLiteral(resourceName: "sunCloudRain"), + "10n":#imageLiteral(resourceName: "moonrain"), + "11d":#imageLiteral(resourceName: "storm"), + "11n":#imageLiteral(resourceName: "storm"), + "13d":#imageLiteral(resourceName: "CloudSnow"), + "13n":#imageLiteral(resourceName: "CloudSnow"), + "50d":#imageLiteral(resourceName: "fog"), + "50n":#imageLiteral(resourceName: "fog") + ] + + private var myCoords: coords = coords() + + override func viewDidLoad() { + super.viewDidLoad() + locationManager = CLLocationManager() + locationManager.delegate = self + locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers + if CLLocationManager.authorizationStatus() == .notDetermined { + locationManager.requestWhenInUseAuthorization() } - private let photoResources: [String: UIImage] = [ - "01d":#imageLiteral(resourceName: "sunny"), - "01n":#imageLiteral(resourceName: "moon"), - "02d":#imageLiteral(resourceName: "sunny_clouds"), - "02n":#imageLiteral(resourceName: "moodCloud"), - "03d":#imageLiteral(resourceName: "clouds"), - "03n":#imageLiteral(resourceName: "clouds"), - "04d":#imageLiteral(resourceName: "clouds"), - "04n":#imageLiteral(resourceName: "clouds"), - "09d":#imageLiteral(resourceName: "cloud_rain"), - "09n":#imageLiteral(resourceName: "cloud_rain"), - "10d":#imageLiteral(resourceName: "sunCloudRain"), - "10n":#imageLiteral(resourceName: "moonrain"), - "11d":#imageLiteral(resourceName: "storm"), - "11n":#imageLiteral(resourceName: "storm"), - "13d":#imageLiteral(resourceName: "CloudSnow"), - "13n":#imageLiteral(resourceName: "CloudSnow"), - "50d":#imageLiteral(resourceName: "fog"), - "50n":#imageLiteral(resourceName: "fog")] - - - private var myCoords: coords = coords() + if CLLocationManager.locationServicesEnabled() { + locationManager.startUpdatingLocation() + } + DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: { + self.updateCurrentForecast() + }) + } + + @IBAction func reloadButtonPressed(_ sender: AnyObject) { + if(CLLocationManager.authorizationStatus() == .notDetermined) { + locationManager.requestWhenInUseAuthorization() + } - override func viewDidLoad() { - super.viewDidLoad() - locationManager = CLLocationManager() - locationManager.delegate = self - locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers - if(CLLocationManager.authorizationStatus() == .notDetermined){ - locationManager.requestWhenInUseAuthorization() - } - - if CLLocationManager.locationServicesEnabled(){ - locationManager.startUpdatingLocation() - } - DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: { - self.updateCurrentForecast() - }) + if CLLocationManager.locationServicesEnabled(){ + locationManager.startUpdatingLocation() } - - @IBAction func reloadButtonPressed(_ sender: AnyObject) { - if(CLLocationManager.authorizationStatus() == .notDetermined){ - locationManager.requestWhenInUseAuthorization() - } - - if CLLocationManager.locationServicesEnabled(){ - locationManager.startUpdatingLocation() + updateCurrentForecast() + } + + internal func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { + print("error: ", error) + } + + internal func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + self.myCoords.lat = locations[0].coordinate.latitude + self.myCoords.lon = locations[0].coordinate.longitude + locationManager.stopUpdatingLocation() + } + + + private func updateCurrentForecast() { + Alamofire.request("http://api.openweathermap.org/data/2.5/weather", method: .get, parameters: ["lat": myCoords.lat, "lon": myCoords.lon, "APPID": "", "units": "metric"], encoding: JSONEncoding.default, headers: nil).responseJSON { [weak self] response in + guard response.result.isSuccess else { + return + } + + let json = JSON(response.result.value as Any) + self?.currentForecast = WeatherForecast(currentWeatherTempurature: round(10 * json["main"]["temp"].doubleValue) / 10, + timeStamp: (self?.getCurrentTime())!, + imageName: json["weather"][0]["icon"].string!, + locationCoordinates: (self?.myCoords.lat, self?.myCoords.lon) as? (Double, Double), + humidity: json["main"]["humidity"].int, + pressure: json["main"]["pressure"].int, + wind: round(10 * json["wind"]["speed"].doubleValue) / 10, cityName: json["name"].string, + stateWeather: json["weather"][0]["description"].string) + } + } + + private func getTrafficInformation() { + Alamofire.request("http://www.mapquestapi.com/traffic/v2/incidents", + parameters: ["boundingBox": "\(myCoords.lat),\(myCoords.lon),\(myCoords.lat - 1),\(myCoords.lon - 1)", + "key": ""]) + .responseJSON{ response in + guard response.result.isSuccess else{ + return } - updateCurrentForecast() + _ = JSON(response.result.value!) } - - - internal func locationManager(_ manager: CLLocationManager, - didFailWithError error: Error) { - print("error: ", error) + } + + private func getCurrentTime() -> String { + let date = Date() + let calendar = Calendar.current + var currentTime: String + let components = calendar.dateComponents([.hour, .minute], from: date as Date!) + var hour: String = String(describing: components.hour!) + var minute: String = String(describing: components.minute!) + if hour.characters.count == 1 { + hour = "0" + hour } - - internal func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { - self.myCoords.lat = locations[0].coordinate.latitude - self.myCoords.lon = locations[0].coordinate.longitude - locationManager.stopUpdatingLocation() + if minute.characters.count == 1 { + minute = "0" + minute } - - - private func updateCurrentForecast(){ - Alamofire.request("http://api.openweathermap.org/data/2.5/weather",method: .get,parameters: ["lat":myCoords.lat,"lon": myCoords.lon,"APPID": "","units":"metric"],encoding: JSONEncoding.default,headers: nil).responseJSON{response in - guard response.result.isSuccess else{ - return - } - let json = JSON(response.result.value!) - self.currentForecast = WeatherForecast(currentWeatherTempurature: round(10 * json["main"]["temp"].doubleValue) / 10, - timeStamp: self.getCurrentTime(), - imageName: json["weather"][0]["icon"].string!, - locationCoordinates: (self.myCoords.lat, self.myCoords.lon), - humidity: json["main"]["humidity"].int, - pressure: json["main"]["pressure"].int, - wind: round(10 * json["wind"]["speed"].doubleValue) / 10, cityName: json["name"].string, - stateWeather: json["weather"][0]["description"].string) - } + currentTime = "\(hour):\(minute)" + return currentTime + } + + private func reloadUI() { + timeLabel.text = "Updated: \(String(describing: currentForecast?.timeStamp))" + if let temp = currentForecast?.currentWeatherTempurature { + temperatureLabel.text = "\(temp)℃" } - - private func getTrafficInformation(){ - Alamofire.request("http://www.mapquestapi.com/traffic/v2/incidents", - parameters: ["boundingBox": "\(myCoords.lat),\(myCoords.lon),\(myCoords.lat - 1),\(myCoords.lon - 1)", - "key": ""]) - .responseJSON{response in - guard response.result.isSuccess else{ - return - } - _ = JSON(response.result.value!) - } + if let city = currentForecast?.cityName { + cityNameLabel.text = city } - - private func getCurrentTime() -> String{ - let date = NSDate() - let calendar = NSCalendar.current - var currentTime: String - let components = calendar.dateComponents([.hour, .minute], from: date as Date!) - var hour: String = String(describing: components.hour!) - var minute: String = String(describing: components.minute!) - if hour.characters.count == 1{ - hour = "0" + hour - } - if(minute.characters.count == 1){ - minute = "0" + minute - } - currentTime = "\(hour):\(minute)" - return currentTime + if let wi = currentForecast?.wind { + windLabel.text = "\(wi)" } - - - - private func reloadUI(){ - timeLabel.text = "Updated: \(currentForecast!.timeStamp)" - if let temp = currentForecast?.currentWeatherTempurature{ - temperatureLabel.text = "\(temp)℃" - } - if let city = currentForecast?.cityName{ - cityNameLabel.text = city - } - if let wi = currentForecast?.wind{ - windLabel.text = "\(wi)" - } - if let st = currentForecast?.stateWeather{ - stateLabel.text = st - } - imageWeather.image = photoResources[(currentForecast?.imageName)!] + if let st = currentForecast?.stateWeather { + stateLabel.text = st } -} - - + imageWeather.image = photoResources[(currentForecast?.imageName)!] + } +} \ No newline at end of file diff --git a/SwiftStyle/Rainy/Rainy/HomeWeatherViewController.swift b/SwiftStyle/Rainy/Rainy/HomeWeatherViewController.swift index 046675e..fb35dc2 100644 --- a/SwiftStyle/Rainy/Rainy/HomeWeatherViewController.swift +++ b/SwiftStyle/Rainy/Rainy/HomeWeatherViewController.swift @@ -1,142 +1,116 @@ -// -// SecondViewController.swift -// Rainy -// -// Created by Kirill Averyanov on 17/10/16. -// Copyright © 2016 Kirill Averyanov. All rights reserved. -// - import UIKit import Alamofire import SwiftyJSON class HomeWeatherViewController: UIViewController { - @IBOutlet weak var timeLabel: UILabel! - @IBOutlet weak var windLabel: UILabel! - @IBOutlet weak var temperatureLabel: UILabel! - @IBOutlet weak var stateLabel: UILabel! - @IBOutlet weak var imageWeatherView: UIImageView! - @IBOutlet weak var cityNameLabel: UILabel! - - private var setts = UserDefaults.standard - private var cityName: String{ - get{ - if let name = setts.value(forKey: "cityName"){ - return name as! String - } - else{ - return "Saint Petersburg" - } - } - }//"Saint Petersburg" -// private let constrain: Constants = Constants() - private var currentForecast: WeatherForecast? { - didSet{ - reloadUI() + @IBOutlet weak var timeLabel: UILabel! + @IBOutlet weak var windLabel: UILabel! + @IBOutlet weak var temperatureLabel: UILabel! + @IBOutlet weak var stateLabel: UILabel! + @IBOutlet weak var imageWeatherView: UIImageView! + @IBOutlet weak var cityNameLabel: UILabel! + + private var setts = UserDefaults.standard + private var cityName: String { + get { + if let name = setts.value(forKey: "cityName") { + return name as! String + } + else { + return "Saint Petersburg" + } + } + } + private var currentForecast: WeatherForecast? { + didSet { + reloadUI() + } + } + + private let photoResources: [String: UIImage] = [ + "01d":#imageLiteral(resourceName: "sunny"), + "01n":#imageLiteral(resourceName: "moon"), + "02d":#imageLiteral(resourceName: "sunny_clouds"), + "02n":#imageLiteral(resourceName: "moodCloud"), + "03d":#imageLiteral(resourceName: "clouds"), + "03n":#imageLiteral(resourceName: "clouds"), + "04d":#imageLiteral(resourceName: "clouds"), + "04n":#imageLiteral(resourceName: "clouds"), + "09d":#imageLiteral(resourceName: "cloud_rain"), + "09n":#imageLiteral(resourceName: "cloud_rain"), + "10d":#imageLiteral(resourceName: "sunCloudRain"), + "10n":#imageLiteral(resourceName: "moonrain"), + "11d":#imageLiteral(resourceName: "storm"), + "11n":#imageLiteral(resourceName: "storm"), + "13d":#imageLiteral(resourceName: "CloudSnow"), + "13n":#imageLiteral(resourceName: "CloudSnow"), + "50d":#imageLiteral(resourceName: "fog"), + "50n":#imageLiteral(resourceName: "fog") + ] + + override func viewDidLoad() { + super.viewDidLoad() + updateCurrentForecast() + } + + // MARK: - refreshButtonPressed + @IBAction func refreshButtonPressed(_ sender: Any) { + updateCurrentForecast() + } + + // MARK: - updateCurrentForecast + private func updateCurrentForecast() { + Alamofire.request("http://api.openweathermap.org/data/2.5/weather", + parameters: ["q": cityName, + "APPID": "","units":"metric"]) + .responseJSON{ [weak self] response in + guard response.result.isSuccess else{ + return } + let json = JSON(response.result.value!) + self?.currentForecast = WeatherForecast(currentWeatherTempurature: round(10 * json["main"]["temp"].doubleValue) / 10, + timeStamp: (self?.getCurrentTime())!, + imageName: json["weather"][0]["icon"].string!, + locationCoordinates: (0, 0), + humidity: json["main"]["humidity"].int, + pressure: json["main"]["pressure"].int, + wind: round(10 * json["wind"]["speed"].doubleValue) / 10, cityName: json["name"].string, + stateWeather: json["weather"][0]["description"].string) } - - private let photoResources: [String: UIImage] = [ - "01d":#imageLiteral(resourceName: "sunny"), - "01n":#imageLiteral(resourceName: "moon"), - "02d":#imageLiteral(resourceName: "sunny_clouds"), - "02n":#imageLiteral(resourceName: "moodCloud"), - "03d":#imageLiteral(resourceName: "clouds"), - "03n":#imageLiteral(resourceName: "clouds"), - "04d":#imageLiteral(resourceName: "clouds"), - "04n":#imageLiteral(resourceName: "clouds"), - "09d":#imageLiteral(resourceName: "cloud_rain"), - "09n":#imageLiteral(resourceName: "cloud_rain"), - "10d":#imageLiteral(resourceName: "sunCloudRain"), - "10n":#imageLiteral(resourceName: "moonrain"), - "11d":#imageLiteral(resourceName: "storm"), - "11n":#imageLiteral(resourceName: "storm"), - "13d":#imageLiteral(resourceName: "CloudSnow"), - "13n":#imageLiteral(resourceName: "CloudSnow"), - "50d":#imageLiteral(resourceName: "fog"), - "50n":#imageLiteral(resourceName: "fog") - ] - - - - override func viewDidLoad() { - super.viewDidLoad() - updateCurrentForecast() + } + + private func getCurrentTime() -> String { + let date = Date() + let calendar = Calendar.current + var currentTime: String + let components = calendar.dateComponents([.hour, .minute], from: date as Date!) + var hour: String = String(describing: components.hour!) + var minute: String = String(describing: components.minute!) + if hour.characters.count == 1 { + hour = "0" + hour } - - - @IBAction func refreshButtonPressed(_ sender: Any) { - updateCurrentForecast() + if minute.characters.count == 1 { + minute = "0" + minute } - - - private func updateCurrentForecast(){ - Alamofire.request("http://api.openweathermap.org/data/2.5/weather", - parameters: ["q": cityName, - "APPID": "","units":"metric"]) - .responseJSON{response in - guard response.result.isSuccess else{ - return - } - let json = JSON(response.result.value!) - self.currentForecast = WeatherForecast(currentWeatherTempurature: round(10 * json["main"]["temp"].doubleValue) / 10, - timeStamp: self.getCurrentTime(), - imageName: json["weather"][0]["icon"].string!, - locationCoordinates: (0, 0), - humidity: json["main"]["humidity"].int, - pressure: json["main"]["pressure"].int, - wind: round(10 * json["wind"]["speed"].doubleValue) / 10, cityName: json["name"].string, - stateWeather: json["weather"][0]["description"].string) - } + currentTime = "\(hour):\(minute)" + return currentTime + } + + private func reloadUI() { + timeLabel.text = "Updated: \(currentForecast!.timeStamp)" + if let temp = currentForecast?.currentWeatherTempurature { + temperatureLabel.text = "\(temp)℃" } - - private func getCurrentTime() -> String{ - let date = NSDate() - let calendar = NSCalendar.current - var currentTime: String - let components = calendar.dateComponents([.hour, .minute], from: date as Date!) - var hour: String = String(describing: components.hour!) - var minute: String = String(describing: components.minute!) - if hour.characters.count == 1{ - hour = "0" + hour - } - if(minute.characters.count == 1){ - minute = "0" + minute - } - currentTime = "\(hour):\(minute)" - return currentTime + if let city = currentForecast?.cityName { + cityNameLabel.text = city } - - private func reloadUI(){ - timeLabel.text = "Updated: \(currentForecast!.timeStamp)" - if let temp = currentForecast?.currentWeatherTempurature{ - temperatureLabel.text = "\(temp)℃" - } - if let city = currentForecast?.cityName{ - cityNameLabel.text = city - } - if let wi = currentForecast?.wind{ - windLabel.text = "\(wi)" - } - if let st = currentForecast?.stateWeather{ - stateLabel.text = st - } - imageWeatherView.image = photoResources[(currentForecast?.imageName)!] + if let wi = currentForecast?.wind { + windLabel.text = "\(wi)" + } + if let st = currentForecast?.stateWeather { + stateLabel.text = st } - - - + imageWeatherView.image = photoResources[(currentForecast?.imageName)!] + } } - - - - - - - - - - - - diff --git a/SwiftStyle/Rainy/Rainy/SettingsViewController.swift b/SwiftStyle/Rainy/Rainy/SettingsViewController.swift index 87461a0..6f442e7 100644 --- a/SwiftStyle/Rainy/Rainy/SettingsViewController.swift +++ b/SwiftStyle/Rainy/Rainy/SettingsViewController.swift @@ -1,36 +1,25 @@ -// -// SettingsViewController.swift -// Rainy -// -// Created by Kirill Averyanov on 30/10/2016. -// Copyright © 2016 Kirill Averyanov. All rights reserved. -// - import UIKit class SettingsViewController: UIViewController { - @IBOutlet weak var textField: UITextField! - @IBOutlet weak var swifthLocation: UISwitch! - - @IBAction func saveButtonPressed(_ sender: Any) { - self.view.endEditing(true) - setts.set(textField.text!, forKey: "cityName") - } - - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - textField.resignFirstResponder() + @IBOutlet weak var textField: UITextField! + @IBOutlet weak var swifthLocation: UISwitch! + @IBAction func saveButtonPressed(_ sender: Any) { + self.view.endEditing(true) + setts.set(textField.text!, forKey: "cityName") + } + + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + textField.resignFirstResponder() + } + + private var setts = UserDefaults.standard + override func viewDidLoad() { + super.viewDidLoad() + if let name = setts.value(forKey: "cityName") { + textField.text = String(describing: name) } - - private var setts = UserDefaults.standard - override func viewDidLoad() { - super.viewDidLoad() - if let name = setts.value(forKey: "cityName"){ - textField.text = String(describing: name) - } - else{ - textField.text = "Saint Petersburg" - } + else { + textField.text = "Saint Petersburg" } - - + } } diff --git a/SwiftStyle/Rainy/Rainy/WeatherForecast.swift b/SwiftStyle/Rainy/Rainy/WeatherForecast.swift index 47152bc..132dc9a 100644 --- a/SwiftStyle/Rainy/Rainy/WeatherForecast.swift +++ b/SwiftStyle/Rainy/Rainy/WeatherForecast.swift @@ -1,41 +1,29 @@ -// -// WeatherForecast.swift -// Rainy -// -// Created by Kirill Averyanov on 17/10/16. -// Copyright © 2016 Kirill Averyanov. All rights reserved. -// - import Foundation - -class WeatherForecast{ - var currentWeatherTempurature: Double? - var timeStamp: String - var imageName: String - var locationCoordinates: (Double, Double)? - var humidity: Int? - var pressure: Int? - var wind: Double? - var cityName: String? - var stateWeather: String? +class WeatherForecast { + var currentWeatherTempurature: Double? + var timeStamp: String + var imageName: String + var locationCoordinates: (Double, Double)? + var humidity: Int? + var pressure: Int? + var wind: Double? + var cityName: String? + var stateWeather: String? + + init(currentWeatherTempurature: Double?, + timeStamp: String, imageName: String, + locationCoordinates: (Double, Double)?, humidity: Int?, pressure: Int?, + wind: Double?, cityName: String?, stateWeather: String?) { - init(currentWeatherTempurature: Double?, - timeStamp: String, imageName: String, - locationCoordinates: (Double, Double)?, humidity: Int?, pressure: Int?, - wind: Double?, cityName: String?, stateWeather: String?) { - - self.currentWeatherTempurature = currentWeatherTempurature - self.timeStamp = timeStamp - self.imageName = imageName - self.locationCoordinates = locationCoordinates - self.humidity = humidity - self.pressure = pressure - self.wind = wind - self.cityName = cityName - self.stateWeather = stateWeather - } + self.currentWeatherTempurature = currentWeatherTempurature + self.timeStamp = timeStamp + self.imageName = imageName + self.locationCoordinates = locationCoordinates + self.humidity = humidity + self.pressure = pressure + self.wind = wind + self.cityName = cityName + self.stateWeather = stateWeather + } } - - -