From fc6ba4d407d6b5ac02771fe49a2a1de9a63319c9 Mon Sep 17 00:00:00 2001 From: jonchui Date: Mon, 15 May 2017 15:48:28 -1000 Subject: [PATCH] Fixes startup crash. by checking for nil, before calling #takeRetainedValue. #26 --- OpenSim/LaunchAtLoginHelper.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/OpenSim/LaunchAtLoginHelper.swift b/OpenSim/LaunchAtLoginHelper.swift index a577a4a..87603e1 100644 --- a/OpenSim/LaunchAtLoginHelper.swift +++ b/OpenSim/LaunchAtLoginHelper.swift @@ -26,10 +26,13 @@ func existingItem(itemUrl: URL) -> LSSharedFileListItem? { if let currentItems = LSSharedFileListCopySnapshot(loginItems, &seed).takeRetainedValue() as? [LSSharedFileListItem] { for item in currentItems { let resolutionFlags = UInt32(kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes) - let url = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, nil).takeRetainedValue() as URL - if itemUrl == url { - return item + if let cfurl = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, nil) { + let url = cfurl.takeRetainedValue() as URL + if itemUrl == url { + return item + } } + } } return nil