Skip to content

Commit 6667e19

Browse files
Michael-AirMapadolfo
authored andcommitted
Bug/nil run loop (aciidgh#41)
* currentRunLoop no long IUO * Ensure currentRunLoop is not nil before trying to remove it from streams
1 parent e412d41 commit 6667e19

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

SwiftMQTT/SwiftMQTT/MQTTSessionStream.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protocol MQTTSessionStreamDelegate: class {
1616

1717
class MQTTSessionStream: NSObject {
1818

19-
private var currentRunLoop: RunLoop!
19+
private var currentRunLoop: RunLoop?
2020
private let inputStream: InputStream?
2121
private let outputStream: OutputStream?
2222
private var sessionQueue: DispatchQueue
@@ -48,8 +48,8 @@ class MQTTSessionStream: NSObject {
4848
}
4949

5050
self.currentRunLoop = RunLoop.current
51-
inputStream?.schedule(in: self.currentRunLoop, forMode: .defaultRunLoopMode)
52-
outputStream?.schedule(in: self.currentRunLoop, forMode: .defaultRunLoopMode)
51+
inputStream?.schedule(in: self.currentRunLoop!, forMode: .defaultRunLoopMode)
52+
outputStream?.schedule(in: self.currentRunLoop!, forMode: .defaultRunLoopMode)
5353

5454
inputStream?.open()
5555
outputStream?.open()
@@ -63,12 +63,13 @@ class MQTTSessionStream: NSObject {
6363
self.connectTimeout()
6464
}
6565
}
66-
self.currentRunLoop.run()
66+
self.currentRunLoop!.run()
6767
}
6868
}
6969

7070
deinit {
7171
delegate = nil
72+
guard let currentRunLoop = currentRunLoop else { return }
7273
inputStream?.close()
7374
inputStream?.remove(from: currentRunLoop, forMode: .defaultRunLoopMode)
7475
outputStream?.close()

0 commit comments

Comments
 (0)