From f0a99b3ceb4eade6d68c1ade24938be28f829b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 15 Apr 2016 10:42:20 +0200 Subject: [PATCH] Swift: a better fix for #161 --- src/iosrtcPlugin.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/iosrtcPlugin.swift b/src/iosrtcPlugin.swift index 79e44f96..338910f8 100644 --- a/src/iosrtcPlugin.swift +++ b/src/iosrtcPlugin.swift @@ -342,20 +342,19 @@ class iosrtcPlugin : CDVPlugin { NSLog("iosrtcPlugin#RTCPeerConnection_close()") let pcId = command.argumentAtIndex(0) as! Int - var pluginRTCPeerConnection = self.pluginRTCPeerConnections[pcId] + let pluginRTCPeerConnection = self.pluginRTCPeerConnections[pcId] if pluginRTCPeerConnection == nil { NSLog("iosrtcPlugin#RTCPeerConnection_close() | ERROR: pluginRTCPeerConnection with pcId=%@ does not exist", String(pcId)) return; } - dispatch_async(self.queue) { + dispatch_async(self.queue) { [weak pluginRTCPeerConnection, unowned self] in pluginRTCPeerConnection!.close() - pluginRTCPeerConnection = nil - } - // Remove the pluginRTCPeerConnection from the dictionary. - self.pluginRTCPeerConnections[pcId] = nil + // Remove the pluginRTCPeerConnection from the dictionary. + self.pluginRTCPeerConnections[pcId] = nil + } }