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: 3 additions & 1 deletion Algorithms/TwoSum.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ let integers: [Int] = [2, 5, 4, 12, 7]
*/
func findTarget(_ target: Int, in array: [Int]) -> [Array<Int>.Index] {
// Ваша реализация



Copy link
Collaborator

Choose a reason for hiding this comment

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

Не нужно столько переводов строк


return [0, 1]
}

Expand Down
6 changes: 3 additions & 3 deletions SwiftStyle/Rainy/Rainy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
TargetAttributes = {
7B11FC391DB53A6900FA6122 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = KH2KDZEEE3;
DevelopmentTeam = DJ22U4RTFT;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
53 changes: 5 additions & 48 deletions SwiftStyle/Rainy/Rainy/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
278 changes: 131 additions & 147 deletions SwiftStyle/Rainy/Rainy/CurrentWeatherViewController.swift
Original file line number Diff line number Diff line change
@@ -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!)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Force castings

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)!]
}
}
Loading