From b3c2e14196555096db327ffe3d1905d0323df565 Mon Sep 17 00:00:00 2001 From: Adolfo Martinelli Date: Fri, 20 Apr 2018 18:21:49 -0700 Subject: [PATCH] Update closure error handling --- .../SwiftMQTTExample/MQTTViewController.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SwiftMQTTExample/SwiftMQTTExample/MQTTViewController.swift b/SwiftMQTTExample/SwiftMQTTExample/MQTTViewController.swift index 365f048..c95e531 100644 --- a/SwiftMQTTExample/SwiftMQTTExample/MQTTViewController.swift +++ b/SwiftMQTTExample/SwiftMQTTExample/MQTTViewController.swift @@ -55,11 +55,10 @@ class MQTTViewController: UIViewController, MQTTSessionDelegate { appendStringToTextView("Trying to connect to \(host) on port \(port) for clientID \(clientID)") mqttSession.connect { (error) in - switch error { - case .none: + if error == .none { self.appendStringToTextView("Connected.") self.subscribeToChannel() - default: + } else { self.appendStringToTextView("Error occurred during connection:") self.appendStringToTextView(error.localizedDescription) } @@ -69,10 +68,9 @@ class MQTTViewController: UIViewController, MQTTSessionDelegate { func subscribeToChannel() { let channel = "/#" mqttSession.subscribe(to: channel, delivering: .atLeastOnce) { (error) in - switch error { - case .none: + if error == .none { self.appendStringToTextView("Subscribed to \(channel)") - default: + } else { self.appendStringToTextView("Error occurred during subscription:") self.appendStringToTextView(error.localizedDescription) }