Skip to content

Commit

Permalink
Fix ASDKgram example #trivial (#700)
Browse files Browse the repository at this point in the history
- Fix an insta-crash that's caused by Webservice.load method to call its completion block off the main thread.
- Fix incorrect http status code check.
- Bump the deployment target to get the project compiling.
  • Loading branch information
onato authored and nguyenhuy committed Dec 20, 2017
1 parent fff5aae commit 4dec51c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -478,7 +478,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
15 changes: 8 additions & 7 deletions examples_extra/ASDKgram-Swift/ASDKgram-Swift/Webservice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ final class WebService {
URLSession.shared.dataTask(with: resource.url) { data, response, error in
// Check for errors in responses.
let result = self.checkForNetworkErrors(data, response, error)

switch result {
case .success(let data):
completion(resource.parse(data))
case .failure(let error):
completion(.failure(error))
DispatchQueue.main.async {
switch result {
case .success(let data):
completion(resource.parse(data))
case .failure(let error):
completion(.failure(error))
}
}
}.resume()
}
Expand All @@ -49,7 +50,7 @@ extension WebService {
}
}

if let response = response as? HTTPURLResponse, response.statusCode >= 200 && response.statusCode <= 299 {
if let response = response as? HTTPURLResponse, response.statusCode <= 200 && response.statusCode >= 299 {
return .failure((.invalidStatusCode("Request returned status code other than 2xx \(response)")))
}

Expand Down

0 comments on commit 4dec51c

Please sign in to comment.