Skip to content

Commit c498e1f

Browse files
committed
Fix JSON parsing for Xcode 9.1 (9B55)
1 parent 7b03f75 commit c498e1f

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
PODS:
2-
- Nimble (7.0.2)
2+
- Nimble (7.0.3)
33
- Quick (1.2.0)
4-
- SwiftyJSON (3.1.4)
4+
- SwiftyJSON (4.0.0)
55

66
DEPENDENCIES:
77
- Nimble
88
- Quick
99
- SwiftyJSON
1010

1111
SPEC CHECKSUMS:
12-
Nimble: bfe1f814edabba69ff145cb1283e04ed636a67f2
12+
Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac
1313
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
14-
SwiftyJSON: c2842d878f95482ffceec5709abc3d05680c0220
14+
SwiftyJSON: 070dabdcb1beb81b247c65ffa3a79dbbfb3b48aa
1515

16-
PODFILE CHECKSUM: 0737c164b0a514aa337a01ca722b89d99ee844b5
16+
PODFILE CHECKSUM: 3509c4c63edbe9a7b092aab021ca4e248077b966
1717

1818
COCOAPODS: 1.3.1

SwiftWeather.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@
546546
);
547547
runOnlyForDeploymentPostprocessing = 0;
548548
shellPath = /bin/sh;
549-
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
549+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
550550
showEnvVarsInLog = 0;
551551
};
552552
875372B40EF6130AA88D65AB /* [CP] Check Pods Manifest.lock */ = {

SwiftWeather/OpenWeatherMapService.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,26 @@ struct OpenWeatherMapService: WeatherServiceProtocol {
5050
}
5151

5252
print(url)
53-
let request = URLRequest(url: url)
54-
let task = session.dataTask(with: request,
55-
completionHandler: { data, response, networkError in
56-
53+
let task = session.dataTask(with: url) { (data, response, error) in
5754
// Check network error
58-
guard networkError == nil else {
55+
guard error == nil else {
5956
let error = SWError(errorCode: .networkRequestFailed)
6057
completionHandler(nil, error)
6158
return
6259
}
63-
60+
6461
// Check JSON serialization error
65-
guard let unwrappedData = data else {
62+
guard let data = data else {
6663
let error = SWError(errorCode: .jsonSerializationFailed)
6764
completionHandler(nil, error)
6865
return
6966
}
7067

71-
let json = JSON(data: unwrappedData)
68+
guard let json = try? JSON(data: data) else {
69+
let error = SWError(errorCode: .jsonParsingFailed)
70+
completionHandler(nil, error)
71+
return
72+
}
7273

7374
// Get temperature, location and icon and check parsing error
7475
guard let tempDegrees = json["list"][0]["main"]["temp"].double,
@@ -89,11 +90,10 @@ struct OpenWeatherMapService: WeatherServiceProtocol {
8990
let weatherIcon = WeatherIcon(condition: weatherCondition, iconString: iconString)
9091
weatherBuilder.iconText = weatherIcon.iconText
9192

92-
9393
weatherBuilder.forecasts = self.getFirstFourForecasts(json)
9494

9595
completionHandler(weatherBuilder.build(), nil)
96-
})
96+
}
9797

9898
task.resume()
9999
}

0 commit comments

Comments
 (0)