Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SwiftStyle/Rainy/Rainy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
7B6889F11DC4F2400014AC1D /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B6889F01DC4F2400014AC1D /* SwiftyJSON.framework */; };
7BDCE5CE1DBBBFE100167625 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BDCE5CD1DBBBFE100167625 /* Alamofire.framework */; settings = {ATTRIBUTES = (Required, ); }; };
8C1C6795E2AFA6AA9F1CF7C5 /* Pods_Rainy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4EA8E15D92D5168D0F28BAE /* Pods_Rainy.framework */; };
E10D115B1FA32EC900649D1F /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = E10D115A1FA32EC900649D1F /* Constants.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -38,6 +39,7 @@
7BDCE5CD1DBBBFE100167625 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Rainy-aldgivkqveeobkekmqalrgpntaib/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.framework"; sourceTree = "<group>"; };
8EBFC4D7F526D8ADA40CD634 /* Pods-Rainy.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rainy.release.xcconfig"; path = "Pods/Target Support Files/Pods-Rainy/Pods-Rainy.release.xcconfig"; sourceTree = "<group>"; };
A34481B21E8E732C8A2F6650 /* Pods-Rainy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rainy.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Rainy/Pods-Rainy.debug.xcconfig"; sourceTree = "<group>"; };
E10D115A1FA32EC900649D1F /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
F4EA8E15D92D5168D0F28BAE /* Pods_Rainy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Rainy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -82,6 +84,7 @@
7B11FC411DB53A6900FA6122 /* HomeWeatherViewController.swift */,
7B6469FA1DC643AE00AA44F2 /* SettingsViewController.swift */,
7B11FC531DB540E900FA6122 /* WeatherForecast.swift */,
E10D115A1FA32EC900649D1F /* Constants.swift */,
7B11FC431DB53A6900FA6122 /* Main.storyboard */,
7B11FC461DB53A6900FA6122 /* Assets.xcassets */,
7B11FC481DB53A6900FA6122 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -249,6 +252,7 @@
7B11FC3E1DB53A6900FA6122 /* AppDelegate.swift in Sources */,
7B11FC401DB53A6900FA6122 /* CurrentWeatherViewController.swift in Sources */,
7B6469FB1DC643AE00AA44F2 /* SettingsViewController.swift in Sources */,
E10D115B1FA32EC900649D1F /* Constants.swift in Sources */,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
32 changes: 0 additions & 32 deletions SwiftStyle/Rainy/Rainy/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,8 @@ 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:.
}


}





46 changes: 46 additions & 0 deletions SwiftStyle/Rainy/Rainy/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Constants.swift
// Rainy
//
// Created by Ekaterina Nesterova on 27.10.2017.
// Copyright © 2017 Kirill Averyanov. All rights reserved.
//

import Foundation

struct URL {

static let weatherURL = "http://api.openweathermap.org/data/2.5/weather"
static let trafficURL = "http://www.mapquestapi.com/traffic/v2/incidents"

}

struct paramKeys {

static let latitude = "lat"
static let longtitude = "lon"
static let addId = "APPID"
static let units = "units"

}

struct paramValues {

static let metric = "metric"

}

struct jsonTags {

static let weather = "weather"
static let temperature = "temp"
static let icon = "icon"
static let jsonMain = "main"
static let humidity = "humidity"
static let pressure = "pressure"
static let wind = "wind"
static let speed = "speed"
static let name = "name"
static let jsonDescription = "description"

}
18 changes: 8 additions & 10 deletions SwiftStyle/Rainy/Rainy/CurrentWeatherViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import CoreLocation
import Alamofire
import SwiftyJSON



struct coords{
var lat: Double = 0
var lon: Double = 0
Expand Down Expand Up @@ -63,7 +61,7 @@ class CurrentWeatherViewController: UIViewController, CLLocationManagerDelegate
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers
if(CLLocationManager.authorizationStatus() == .notDetermined){
if(CLLocationManager.authorizationStatus() == .notDetermined) {
locationManager.requestWhenInUseAuthorization()
}

Expand All @@ -80,7 +78,7 @@ class CurrentWeatherViewController: UIViewController, CLLocationManagerDelegate
locationManager.requestWhenInUseAuthorization()
}

if CLLocationManager.locationServicesEnabled(){
if CLLocationManager.locationServicesEnabled() {
locationManager.startUpdatingLocation()
}
updateCurrentForecast()
Expand All @@ -100,24 +98,24 @@ class CurrentWeatherViewController: UIViewController, CLLocationManagerDelegate


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
Alamofire.request(URL.weatherURL, method: .get,parameters: [paramKeys.latitude:myCoords.lat,paramKeys.longtitude: myCoords.lon,paramKeys.addId: "",paramKeys.units:paramValues.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,
self.currentForecast = WeatherForecast(currentWeatherTempurature: round(10 * json[jsonTags.jsonMain][jsonTags.temperature].doubleValue) / 10,
timeStamp: self.getCurrentTime(),
imageName: json["weather"][0]["icon"].string!,
imageName: json[jsonTags.jsonMain][0][jsonTags.icon].string!,
locationCoordinates: (self.myCoords.lat, self.myCoords.lon),
humidity: json["main"]["humidity"].int,
pressure: json["main"]["pressure"].int,
humidity: json[jsonTags.jsonMain][jsonTags.humidity].int,
pressure: json[jsonTags.jsonMain]["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",
Alamofire.request(URL.trafficURL,
parameters: ["boundingBox": "\(myCoords.lat),\(myCoords.lon),\(myCoords.lat - 1),\(myCoords.lon - 1)",
"key": ""])
.responseJSON{response in
Expand Down
41 changes: 20 additions & 21 deletions SwiftStyle/Rainy/Rainy/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@
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<UITouch>, with event: UIEvent?) {
@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<UITouch>, 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"
}

}

}