Skip to content

Commit 148c5d5

Browse files
authored
Merge pull request #8 from carambalabs/feature/swift-3.0
Swift 3.0 Support
2 parents 76a3002 + 038c6ec commit 148c5d5

17 files changed

+107
-68
lines changed

.hound.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
swift:
2+
config_file: .swiftlint.yml

.swiftlint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
disabled_rules:
2+
- colon
3+
- comma
4+
- control_statement
5+
- force_cast
6+
included:
7+
- ../UnsplashKit
8+
excluded:
9+
- ../Example
10+
- ../fastlane
11+
force_cast: warning
12+
force_try:
13+
severity: warning
14+
line_length: 180
15+
type_body_length:
16+
warning: 300
17+
error: 400
18+
file_length:
19+
warning: 500
20+
error: 1200
21+
type_name:
22+
min_length: 3
23+
max_length:
24+
warning: 40
25+
error: 50
26+
variable_name:
27+
min_length:
28+
error: 3
29+
reporter: "xcode"

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
osx_image: xcode7.3
1+
osx_image: xcode8
22
language: objective-c
33
notifications:
44
email: false

DarkSkyKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Swift client for darksky.net API
1212
s.source = { :git => 'https://github.com/carambalabs/DarkSkyKit.git', :tag => s.version.to_s }
1313
s.ios.deployment_target = '8.0'
1414
s.source_files = 'DarkSkyKit/**/*'
15-
s.dependency 'Alamofire/Alamofire', '~> 3.5.0'
15+
s.dependency 'Alamofire/Alamofire', '~> 4.0.0'
1616
s.ios.deployment_target = '8.0'
1717
s.osx.deployment_target = '10.10'
1818
s.tvos.deployment_target = '9.0'

DarkSkyKit/Current.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import Foundation
22
import Alamofire
33

44
public extension DarkSkyKit {
5-
public func current(latitude lat: Double, longitude long: Double, result: Result<Forecast, NSError> -> Void) {
6-
Alamofire.request(Router.Current(configuration, lat, long)).responseJSON { response in
5+
public func current(latitude lat: Double, longitude long: Double, result: @escaping (Result<Forecast>) -> Void) {
6+
Alamofire.request(Router.current(configuration, lat, long)).responseJSON { response in
77
switch response.result {
8-
case .Success(let value):
8+
case .success(let value):
99
if let json = value as? [String:AnyObject] {
10-
result(Result.Success(Forecast(data: json)))
10+
result(Result.success(Forecast(data: json)))
1111
}
12-
case .Failure(let error):
13-
result(Result.Failure(error))
12+
case .failure(let error):
13+
result(Result.failure(error))
1414
}
1515
}
1616
}

DarkSkyKit/Forecast.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public struct Forecast {
4444
}
4545
}
4646

47-
extension NSDate {
48-
convenience init?(time: Double?) {
47+
extension Date {
48+
init?(time: Double?) {
4949
guard let t = time else { return nil }
5050
self.init(timeIntervalSince1970: t)
5151
}

DarkSkyKit/Models/ForecastAlert.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import Foundation
22

33
public struct ForecastAlert {
44
var title: String?
5-
var expires: NSDate?
5+
var expires: Date?
66
var description: String?
77
var uri: String?
88

9-
static func map(data: [String: AnyObject]) -> ForecastAlert {
9+
static func map(_ data: [String: AnyObject]) -> ForecastAlert {
1010
var a = ForecastAlert()
1111
a.title = data["title"] as? String ?? nil
12-
a.expires = NSDate(time: data["expires"] as? Double)
12+
a.expires = Date(time: data["expires"] as? Double)
1313
a.description = data["description"] as? String ?? nil
1414
a.uri = data["uri"] as? String ?? nil
1515
return a

DarkSkyKit/Models/ForecastDataPoint.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import Foundation
22

33
public struct ForecastDataPoint {
4-
var time: NSDate?
4+
var time: Date?
55
var summary: String?
66
var icon: String?
7-
var sunriseTime: NSDate?
8-
var sunsetTime: NSDate?
7+
var sunriseTime: Date?
8+
var sunsetTime: Date?
99
var moonPhase: Double?
1010
var nearestStormDistance: Double?
1111
var nearestStormBearing: Double?
1212
var precipIntensity: Double?
1313
var precipIntensityMax: Double?
14-
var precipIntensityMaxTime: NSDate?
14+
var precipIntensityMaxTime: Date?
1515
var precipProbability: Double?
1616
var precipType: String?
1717
var precipAccumulation: Double?
1818
var temperature: Double?
1919
var temperatureMin: Double?
20-
var temperatureMinTime: NSDate?
20+
var temperatureMinTime: Date?
2121
var temperatureMax: Double?
22-
var temperatureMaxTime: NSDate?
22+
var temperatureMaxTime: Date?
2323
var apparentTemperature: Double?
2424
var apparentTemperatureMin: Double?
25-
var apparentTemperatureMinTime: NSDate?
25+
var apparentTemperatureMinTime: Date?
2626
var apparentTemperatureMax: Double?
27-
var apparentTemperatureMaxTime: NSDate?
27+
var apparentTemperatureMaxTime: Date?
2828
var dewPoint: Double?
2929
var windSpeed: Double?
3030
var windBearing: Double?
@@ -34,32 +34,32 @@ public struct ForecastDataPoint {
3434
var visibility: Double?
3535
var ozone: Double?
3636

37-
static func map(data: [String: AnyObject]) -> ForecastDataPoint {
37+
static func map(_ data: [String: AnyObject]) -> ForecastDataPoint {
3838
var p = ForecastDataPoint()
39-
p.time = NSDate(time: data["time"] as? Double)
39+
p.time = Date(time: data["time"] as? Double)
4040
p.summary = data["summary"] as? String ?? ""
4141
p.icon = data["icon"] as? String ?? ""
42-
p.sunriseTime = NSDate(time: data["sunriseTime"] as? Double)
43-
p.sunsetTime = NSDate(time: data["sunsetTime"] as? Double)
42+
p.sunriseTime = Date(time: data["sunriseTime"] as? Double)
43+
p.sunsetTime = Date(time: data["sunsetTime"] as? Double)
4444
p.moonPhase = data["moonPhase"] as? Double ?? nil
4545
p.nearestStormDistance = data["nearestStormDistance"] as? Double ?? nil
4646
p.nearestStormBearing = data["nearestStormBearing"] as? Double ?? nil
4747
p.precipIntensity = data["precipIntensity"] as? Double ?? nil
4848
p.precipIntensityMax = data["precipIntensityMax"] as? Double ?? nil
49-
p.precipIntensityMaxTime = NSDate(time: data["precipIntensityMaxTime"] as? Double)
49+
p.precipIntensityMaxTime = Date(time: data["precipIntensityMaxTime"] as? Double)
5050
p.precipProbability = data["precipProbability"] as? Double ?? nil
5151
p.precipType = data["precipType"] as? String ?? nil
5252
p.precipAccumulation = data["precipAccumulation"] as? Double ?? nil
5353
p.temperature = data["temperature"] as? Double ?? nil
5454
p.temperatureMin = data["temperatureMin"] as? Double ?? nil
55-
p.temperatureMinTime = NSDate(time: data["temperatureMinTime"] as? Double)
55+
p.temperatureMinTime = Date(time: data["temperatureMinTime"] as? Double)
5656
p.temperatureMax = data["temperatureMax"] as? Double ?? nil
57-
p.temperatureMaxTime = NSDate(time: data["temperatureMaxTime"] as? Double)
57+
p.temperatureMaxTime = Date(time: data["temperatureMaxTime"] as? Double)
5858
p.apparentTemperature = data["apparentTemperature"] as? Double ?? nil
5959
p.apparentTemperatureMin = data["apparentTemperatureMin"] as? Double ?? nil
60-
p.apparentTemperatureMinTime = NSDate(time: data["apparentTemperatureMinTime"] as? Double)
60+
p.apparentTemperatureMinTime = Date(time: data["apparentTemperatureMinTime"] as? Double)
6161
p.apparentTemperatureMax = data["apparentTemperatureMax"] as? Double ?? nil
62-
p.apparentTemperatureMaxTime = NSDate(time: data["apparentTemperatureMaxTime"] as? Double)
62+
p.apparentTemperatureMaxTime = Date(time: data["apparentTemperatureMaxTime"] as? Double)
6363
p.dewPoint = data["dewPoint"] as? Double ?? nil
6464
p.windSpeed = data["windSpeed"] as? Double ?? nil
6565
p.windBearing = data["windBearing"] as? Double ?? nil

DarkSkyKit/Models/ForecastFlags.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct ForecastFlags {
1111
var sources: [String]?
1212
var units: String?
1313

14-
static func map(data: [String: AnyObject]) -> ForecastFlags {
14+
static func map(_ data: [String: AnyObject]) -> ForecastFlags {
1515
var f = ForecastFlags()
1616
f.darkskyStations = data["darksky-stations"] as? [String] ?? nil
1717
f.datapointStations = data["datapoint-stations"] as? [String] ?? nil

DarkSkyKit/Router.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,55 @@ import Foundation
22
import Alamofire
33

44
enum Router: URLRequestConvertible {
5-
private static let baseURLString = "https://api.darksky.net"
65

7-
case Current(Configuration, Double, Double)
8-
case TimeMachine(Configuration, Double, Double, NSDate)
6+
fileprivate static let baseURLString = "https://api.darksky.net"
97

10-
var method: Alamofire.Method {
11-
return .GET
8+
case current(Configuration, Double, Double)
9+
case timeMachine(Configuration, Double, Double, Date)
10+
11+
var method: HTTPMethod {
12+
return .get
1213
}
1314

1415
var path: String {
1516
switch self {
16-
case .Current(let c, let lat, let long):
17+
case .current(let c, let lat, let long):
1718
return "/forecast/\(c.token)/\(lat),\(long)"
18-
case .TimeMachine(let c, let lat, let long, let date):
19+
case .timeMachine(let c, let lat, let long, let date):
1920
return "/forecast/\(c.token)/\(lat),\(long),\(date.timeIntervalSince1970)"
2021
}
2122
}
2223

2324
var params: [String: AnyObject] {
2425
var configuration: Configuration
2526
switch self {
26-
case .Current(let c, _, _):
27+
case .current(let c, _, _):
2728
configuration = c
28-
case .TimeMachine(let c, _, _, _):
29+
case .timeMachine(let c, _, _, _):
2930
configuration = c
3031
}
3132

3233
var parameters = [String: AnyObject]()
3334
if let units = configuration.units {
34-
parameters.updateValue(units.rawValue, forKey: "units")
35+
parameters.updateValue(units.rawValue as AnyObject, forKey: "units")
3536
}
3637
if let exclude = configuration.exclude {
37-
parameters.updateValue(exclude.rawValue, forKey: "exclude")
38+
parameters.updateValue(exclude.rawValue as AnyObject, forKey: "exclude")
3839
}
3940
if let extend = configuration.extend {
40-
parameters.updateValue(extend.rawValue, forKey: "extend")
41+
parameters.updateValue(extend.rawValue as AnyObject, forKey: "extend")
4142
}
4243
if let lang = configuration.lang {
43-
parameters.updateValue(lang, forKey: "lang")
44+
parameters.updateValue(lang as AnyObject, forKey: "lang")
4445
}
4546
return parameters
4647
}
4748

48-
var URLRequest: NSMutableURLRequest {
49-
let URL = NSURL(string: Router.baseURLString)!
50-
let mutableURLRequest = NSMutableURLRequest(URL: URL.URLByAppendingPathComponent(path)!)
51-
mutableURLRequest.HTTPMethod = method.rawValue
52-
return Alamofire.ParameterEncoding.URL.encode(mutableURLRequest, parameters: self.params).0
49+
func asURLRequest() throws -> URLRequest {
50+
let url = try Router.baseURLString.asURL()
51+
var urlRequest = URLRequest(url: url.appendingPathComponent(path))
52+
urlRequest.httpMethod = method.rawValue
53+
urlRequest = try URLEncoding.default.encode(urlRequest, with: self.params)
54+
return urlRequest
5355
}
5456
}

DarkSkyKit/TimeMachine.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import Foundation
22
import Alamofire
33

44
public extension DarkSkyKit {
5-
public func timeMachine(latitude lat: Double, lognitude long: Double, date: NSDate, result: Result<Forecast, NSError> -> Void) {
6-
Alamofire.request(Router.TimeMachine(configuration, lat, long, date)).responseJSON { response in
5+
public func timeMachine(latitude lat: Double, lognitude long: Double, date: Date, result: @escaping (Result<Forecast>) -> Void) {
6+
Alamofire.request(Router.timeMachine(configuration, lat, long, date)).responseJSON { response in
77
switch response.result {
8-
case .Success(let value):
8+
case .success(let value):
99
if let json = value as? [String:AnyObject] {
10-
result(Result.Success(Forecast(data: json)))
10+
result(Result.success(Forecast(data: json)))
1111
}
12-
case .Failure(let error):
13-
result(Result.Failure(error))
12+
case .failure(let error):
13+
result(Result.failure(error))
1414
}
1515
}
1616
}

Example/DarkSkyKitExample.xcodeproj/project.pbxproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@
252252
TargetAttributes = {
253253
5525DC7B1D3D8ACA00D3967C = {
254254
CreatedOnToolsVersion = 7.3.1;
255+
LastSwiftMigration = 0800;
255256
};
256257
5525DC841D3D8ACA00D3967C = {
257258
CreatedOnToolsVersion = 7.3.1;
259+
LastSwiftMigration = 0800;
258260
};
259261
};
260262
};
@@ -462,7 +464,7 @@
462464
ONLY_ACTIVE_ARCH = YES;
463465
SDKROOT = iphoneos;
464466
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
465-
SWIFT_VERSION = 2.3;
467+
SWIFT_VERSION = 3.0;
466468
TARGETED_DEVICE_FAMILY = "1,2";
467469
};
468470
name = Debug;
@@ -501,7 +503,7 @@
501503
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
502504
MTL_ENABLE_DEBUG_INFO = NO;
503505
SDKROOT = iphoneos;
504-
SWIFT_VERSION = 2.3;
506+
SWIFT_VERSION = 3.0;
505507
TARGETED_DEVICE_FAMILY = "1,2";
506508
VALIDATE_PRODUCT = YES;
507509
};
@@ -525,6 +527,7 @@
525527
PRODUCT_NAME = "$(TARGET_NAME)";
526528
SKIP_INSTALL = YES;
527529
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
530+
SWIFT_VERSION = 3.0;
528531
VERSIONING_SYSTEM = "apple-generic";
529532
VERSION_INFO_PREFIX = "";
530533
};
@@ -547,6 +550,7 @@
547550
PRODUCT_BUNDLE_IDENTIFIER = com.sergigracia.DarkSkyKitExample;
548551
PRODUCT_NAME = "$(TARGET_NAME)";
549552
SKIP_INSTALL = YES;
553+
SWIFT_VERSION = 3.0;
550554
VERSIONING_SYSTEM = "apple-generic";
551555
VERSION_INFO_PREFIX = "";
552556
};
@@ -562,6 +566,7 @@
562566
PRODUCT_BUNDLE_IDENTIFIER = com.sergigracia.DarkSkyKitExampleTests;
563567
PRODUCT_NAME = "$(TARGET_NAME)";
564568
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
569+
SWIFT_VERSION = 3.0;
565570
};
566571
name = Debug;
567572
};
@@ -574,6 +579,7 @@
574579
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)";
575580
PRODUCT_BUNDLE_IDENTIFIER = com.sergigracia.DarkSkyKitExampleTests;
576581
PRODUCT_NAME = "$(TARGET_NAME)";
582+
SWIFT_VERSION = 3.0;
577583
};
578584
name = Release;
579585
};

Example/DarkSkyKitTests/ForecastFlagsTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import Foundation
44
class ForecastFlagsTests: XCTestCase {
55
func testForecastFlagsMap() {
66

7-
if let path = NSBundle.mainBundle().pathForResource("flags", ofType: "json") {
8-
let data = try! NSData(contentsOfURL: NSURL(fileURLWithPath: path), options: .DataReadingMappedIfSafe)
9-
if let jsonResult: NSDictionary = try! NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary {
7+
if let path = Bundle.main.path(forResource: "flags", ofType: "json") {
8+
let data = try! Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
9+
if let jsonResult: NSDictionary = try! JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? NSDictionary {
1010
print(jsonResult)
1111
}
1212
}

Example/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ source 'https://github.com/CocoaPods/Specs.git'
22

33
target 'DarkSkyKitExample' do
44
use_frameworks!
5-
pod 'Alamofire', '3.5.0'
5+
pod 'Alamofire', '4.0.0'
66

77
target 'DarkSkyKitExampleTests' do
88
inherit! :search_paths

Example/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
PODS:
2-
- Alamofire (3.5.0)
2+
- Alamofire (4.0.0)
33

44
DEPENDENCIES:
5-
- Alamofire (= 3.5.0)
5+
- Alamofire (= 4.0.0)
66

77
SPEC CHECKSUMS:
8-
Alamofire: b70a7352335f8ea5babd0a923eb7e8eacc67b877
8+
Alamofire: fef59f00388f267e52d9b432aa5d93dc97190f14
99

10-
PODFILE CHECKSUM: 5489311a34984862ecdff15e61c485326f5567ba
10+
PODFILE CHECKSUM: 52031aac8ee284d495b690fb6c6d22cd5a5fe13a
1111

1212
COCOAPODS: 1.1.0.rc.2

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source "https://rubygems.org"
22

3-
gem "cocoapods", "1.1.0.rc.2"
3+
gem "cocoapods"
44
gem "fastlane"
55
gem "versionomy"
66

0 commit comments

Comments
 (0)