Skip to content

Commit 37b0a48

Browse files
authored
Merge pull request #52 from mstrzele/master
Add SwiftLint configuration and correct warnings and errors
2 parents c958440 + 03c5d9a commit 37b0a48

20 files changed

Lines changed: 212 additions & 175 deletions

.swiftlint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
excluded:
2+
- Pods

SwiftWeather/AppDelegate.swift

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,46 @@ import UIKit
1010

1111
@UIApplicationMain
1212
class AppDelegate: UIResponder, UIApplicationDelegate {
13-
13+
1414
var window: UIWindow?
15-
16-
17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
15+
16+
17+
func application(application: UIApplication,
18+
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1819
// Override point for customization after application launch.
1920
return true
2021
}
21-
22+
2223
func applicationWillResignActive(application: UIApplication) {
23-
// 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.
24-
// 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.
24+
// Sent when the application is about to move from active to inactive state. This can occur for
25+
// certain types of temporary interruptions (such as an incoming phone call or SMS message) or
26+
// when the user quits the application and it begins the transition to the background state.
27+
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame
28+
// rates. Games should use this method to pause the game.
2529
}
26-
30+
2731
func applicationDidEnterBackground(application: UIApplication) {
28-
// 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.
29-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
32+
// Use this method to release shared resources, save user data, invalidate timers, and store
33+
// enough application state information to restore your application to its current state in case
34+
// it is terminated later.
35+
// If your application supports background execution, this method is called instead of
36+
// applicationWillTerminate: when the user quits.
3037
}
31-
38+
3239
func applicationWillEnterForeground(application: UIApplication) {
33-
// 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.
40+
// Called as part of the transition from the background to the inactive state; here you can undo
41+
// many of the changes made on entering the background.
3442
}
35-
43+
3644
func applicationDidBecomeActive(application: UIApplication) {
37-
// 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.
45+
// Restart any tasks that were paused (or not yet started) while the application was inactive.
46+
// If the application was previously in the background, optionally refresh the user interface.
3847
}
39-
48+
4049
func applicationWillTerminate(application: UIApplication) {
41-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
50+
// Called when the application is about to terminate. Save data if appropriate. See also
51+
// applicationDidEnterBackground:.
4252
}
43-
44-
53+
54+
4555
}

SwiftWeather/Error.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ struct Error {
1212
case JSONSerializationFailed = -6002
1313
case JSONParsingFailed = -6003
1414
}
15-
15+
1616
let errorCode: Code
17-
}
17+
}

SwiftWeather/ForecastDateTime.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import Foundation
77

88
struct ForecastDateTime {
99
let rawDate: Double
10-
10+
1111
init(_ date: Double) {
1212
rawDate = date
1313
}
14-
14+
1515
var shortTime: String {
1616
let dateFormatter = NSDateFormatter()
1717
dateFormatter.dateFormat = "HH:mm"

SwiftWeather/ForecastView.swift

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,32 @@ import UIKit
88
@IBDesignable class ForecastView: UIView {
99
// Our custom view from the XIB file
1010
var view: UIView!
11-
11+
1212
@IBOutlet weak var timeLabel: UILabel!
1313
@IBOutlet weak var iconLabel: UILabel!
1414
@IBOutlet weak var temperatureLabel: UILabel!
15-
15+
1616
// MARK: - init
1717
override init(frame: CGRect) {
1818
super.init(frame: frame)
1919
view = loadViewFromNib()
2020
}
21-
21+
2222
required init?(coder aDecoder: NSCoder) {
2323
super.init(coder: aDecoder)
2424
view = loadViewFromNib()
2525
}
26-
26+
2727
func loadViewFromNib() -> UIView {
2828
let bundle = NSBundle(forClass: self.dynamicType)
2929
let nib = UINib(nibName: nibName(), bundle: bundle)
30+
// swiftlint:disable force_cast
3031
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
31-
32+
// swiftlint:enable force_cast
33+
3234
view.frame = bounds
3335
view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
34-
addSubview(view);
36+
addSubview(view)
3537
return view
3638
}
3739

@@ -58,78 +60,78 @@ import UIKit
5860
func loadViewModel(viewModel: ForecastViewModel) {
5961
self.viewModel = viewModel
6062
}
61-
63+
6264
// MARK: - IBInspectable
6365
@IBInspectable var time: String? {
6466
get {
6567
return timeLabel.text
6668
}
67-
69+
6870
set {
6971
timeLabel.text = newValue
7072
}
7173
}
72-
74+
7375
@IBInspectable var icon: String? {
7476
get {
7577
return iconLabel.text
7678
}
77-
79+
7880
set {
7981
iconLabel.text = newValue
8082
}
8183
}
82-
84+
8385
@IBInspectable var temperature: String? {
8486
get {
8587
return temperatureLabel.text
8688
}
87-
89+
8890
set {
8991
temperatureLabel.text = newValue
9092
}
9193
}
92-
94+
9395
@IBInspectable var timeColor: UIColor {
9496
get {
9597
return timeLabel.textColor
9698
}
97-
99+
98100
set {
99101
timeLabel.textColor = newValue
100102
}
101103
}
102-
104+
103105
@IBInspectable var iconColor: UIColor {
104106
get {
105107
return iconLabel.textColor
106108
}
107-
109+
108110
set {
109111
iconLabel.textColor = newValue
110112
}
111113
}
112-
114+
113115
@IBInspectable var temperatureColor: UIColor {
114116
get {
115117
return temperatureLabel.textColor
116118
}
117-
119+
118120
set {
119121
temperatureLabel.textColor = newValue
120122
}
121123
}
122-
124+
123125
@IBInspectable var bgColor: UIColor {
124126
get {
125127
return view.backgroundColor!
126128
}
127-
129+
128130
set {
129131
view.backgroundColor = newValue
130132
}
131133
}
132-
134+
133135
// MARK: - Private
134136
private func nibName() -> String {
135137
return String(self.dynamicType)

SwiftWeather/ForecastViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct ForecastViewModel {
99
let time: Observable<String>
1010
let iconText: Observable<String>
1111
let temperature: Observable<String>
12-
12+
1313
init(_ forecast: Forecast) {
1414
time = Observable(forecast.time)
1515
iconText = Observable(forecast.iconText)

SwiftWeather/LocationService.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ protocol LocationServiceDelegate {
1010
func locationDidUpdate(service: LocationService, location: CLLocation)
1111
}
1212

13-
class LocationService : NSObject {
13+
class LocationService: NSObject {
1414
var delegate: LocationServiceDelegate?
15-
15+
1616
private let locationManager = CLLocationManager()
17-
17+
1818
override init() {
1919
super.init()
20-
20+
2121
locationManager.delegate = self
2222
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
2323
}
24-
24+
2525
func requestLocation() {
2626
locationManager.requestWhenInUseAuthorization()
2727
locationManager.requestLocation()
@@ -33,11 +33,11 @@ extension LocationService : CLLocationManagerDelegate {
3333
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
3434
if let location = locations.first {
3535
print("Current location: \(location)")
36-
delegate?.locationDidUpdate(self, location: location);
36+
delegate?.locationDidUpdate(self, location: location)
3737
}
3838
}
39-
39+
4040
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
4141
print("Error finding location: \(error.localizedDescription)")
4242
}
43-
}
43+
}

SwiftWeather/Observable.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import Foundation
88
class Observable<T> {
99
typealias Observer = T -> Void
1010
var observer: Observer?
11-
11+
1212
func observe(observer: Observer?) {
1313
self.observer = observer
1414
observer?(value)
1515
}
16-
16+
1717
var value: T {
1818
didSet {
1919
observer?(value)
2020
}
2121
}
22-
23-
init(_ v: T) {
24-
value = v
22+
23+
init(_ value: T) {
24+
self.value = value
2525
}
2626
}

0 commit comments

Comments
 (0)