From b3277bfa4b617f318ae5e233e653875907e37f9b Mon Sep 17 00:00:00 2001 From: Tate Johnson Date: Wed, 22 Jul 2015 20:03:24 +1000 Subject: [PATCH] Completion handlers should fire anyway. --- Source/Client.swift | 13 +++++++------ Source/LightTarget.swift | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Client.swift b/Source/Client.swift index 35dfbb2..5d2c34c 100644 --- a/Source/Client.swift +++ b/Source/Client.swift @@ -24,12 +24,12 @@ public class Client { public func fetch(completionHandler: ((error: NSError?) -> Void)? = nil) { session.lights(selector: "all") { [weak self] (request, response, lights, error) in - if let strongSelf = self { - if error != nil { - completionHandler?(error: error) - return - } + if error != nil { + completionHandler?(error: error) + return + } + if let strongSelf = self { let oldLights = strongSelf.lights let newLights = lights if oldLights != newLights { @@ -39,8 +39,9 @@ public class Client { } } - completionHandler?(error: nil) } + + completionHandler?(error: nil) } } diff --git a/Source/LightTarget.swift b/Source/LightTarget.swift index 8b3d514..0629515 100644 --- a/Source/LightTarget.swift +++ b/Source/LightTarget.swift @@ -122,8 +122,8 @@ public class LightTarget { newLights = newLights.map({ $0.lightWithPower(oldPower) }) } strongSelf.client.updateLights(newLights) - completionHandler?(results: results, error: error) } + completionHandler?(results: results, error: error) } } @@ -148,8 +148,8 @@ public class LightTarget { newLights = newLights.map({ $0.lightWithColor(oldColor, andBrightness: oldBrightness) }) } strongSelf.client.updateLights(newLights) - completionHandler?(results: results, error: error) } + completionHandler?(results: results, error: error) } }