From 22d654dd692d3d5df15606940c020d88537bcc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E5=85=B5?= Date: Mon, 17 Oct 2016 16:13:42 +0800 Subject: [PATCH] defaults.array(forKey: "ServerProfiles") would return nil ,but not handle --- ShadowsocksX-NG/AppDelegate.swift | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index 60796e8..dcff1ca 100755 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -385,16 +385,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele showRunningModeMenuItem.state = defaults.bool(forKey: "ShowRunningModeOnStatusBar") ? 1 : 0 var serverMenuText = "Servers".localized - for v in defaults.array(forKey: "ServerProfiles")! { - let profile = v as! [String:Any] - if profile["Id"] as! String == defaults.string(forKey: "ActiveServerProfileId")! { - var profileName :String - if profile["Remark"] as! String != "" { - profileName = profile["Remark"] as! String - } else { - profileName = profile["ServerHost"] as! String + if let serverProfiles = defaults.array(forKey: "ServerProfiles") { + for v in serverProfiles { + let profile = v as! [String:Any] + if profile["Id"] as! String == defaults.string(forKey: "ActiveServerProfileId")! { + var profileName :String + if profile["Remark"] as! String != "" { + profileName = profile["Remark"] as! String + } else { + profileName = profile["ServerHost"] as! String + } + serverMenuText = "\(serverMenuText) - \(profileName)" } - serverMenuText = "\(serverMenuText) - \(profileName)" } } serversMenuItem.title = serverMenuText