From c60888f61aae5f14a561652dd5c774cc47f72e1a Mon Sep 17 00:00:00 2001 From: Wasin Thonkaew Date: Sat, 1 Apr 2017 19:46:57 +0700 Subject: [PATCH] Prevent crash from code as we noted in Code Notices --- Potatso/Core/API.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Potatso/Core/API.swift b/Potatso/Core/API.swift index 00caddbd..43ed4d0a 100644 --- a/Potatso/Core/API.swift +++ b/Potatso/Core/API.swift @@ -244,14 +244,17 @@ extension Alamofire.DataRequest { let JSONToMap: AnyObject? if let keyPath = keyPath, keyPath.isEmpty == false { + // issue: see Code Notices at Github's front page, still no time to pay attention to this issue yet... //JSONToMap = (result.value? as AnyObject).value(forKeyPath: keyPath) JSONToMap = nil } else { JSONToMap = result.value as AnyObject? } - if let parsedObject = Mapper().mapArray(JSONArray: JSONToMap as! [[String : Any]]){ - return .success(parsedObject) + if (JSONToMap != nil) { + if let parsedObject = Mapper().mapArray(JSONArray: JSONToMap as! [[String : Any]]){ + return .success(parsedObject) + } } let failureReason = "ObjectMapper failed to serialize response."