Skip to content

Commit

Permalink
Client#fetch should also use a weak reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatey committed Jul 22, 2015
1 parent 6d74522 commit 0705986
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions Source/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ public class Client {
}

public func fetch(completionHandler: ((error: NSError?) -> Void)? = nil) {
session.lights(selector: "all") { [unowned self] (request, response, lights, error) in
if error != nil {
completionHandler?(error: error)
return
}
session.lights(selector: "all") { [weak self] (request, response, lights, error) in
if let strongSelf = self {
if error != nil {
completionHandler?(error: error)
return
}

let oldLights = self.lights
let newLights = lights
if oldLights != newLights {
self.lights = newLights
for observer in self.observers {
observer.lightsDidUpdateHandler(lights: lights)
let oldLights = strongSelf.lights
let newLights = lights
if oldLights != newLights {
strongSelf.lights = newLights
for observer in strongSelf.observers {
observer.lightsDidUpdateHandler(lights: lights)
}
}
}

completionHandler?(error: nil)
completionHandler?(error: nil)
}
}
}

Expand Down

0 comments on commit 0705986

Please sign in to comment.