Index: iOS/SiteStorage.swift ================================================================== --- iOS/SiteStorage.swift +++ iOS/SiteStorage.swift @@ -32,41 +32,40 @@ private var storage: [String: [NSNumber: AnyObject]] private var sites: [String] override init() { let fileManager = OFFileManager.default - let userDataPath = OFSystemInfo.userDataPath! + let userDataURL = OFSystemInfo.userDataURL! - if !fileManager.directoryExists(atPath: userDataPath) { - fileManager.createDirectory(atPath: userDataPath) + if !fileManager.directoryExists(at: userDataURL) { + fileManager.createDirectory(at: userDataURL) } - let path = userDataPath.appendingPathComponent( + let URL = userDataURL.appendingPathComponent( OFString(utf8String: "sites.msgpack")) var storage: [String: [NSNumber: AnyObject]]? = nil OFException.try({ - let decoded = (OFData(contentsOfFile: path) - .objectByParsingMessagePack) + let decoded = (OFData(contentsOf: URL).objectByParsingMessagePack) as? OFDictionary> storage = (decoded?.nsObject as? [String: [NSNumber: AnyObject]]) ?? [:] }, catch: { (OFException) in storage = [:] }) - self.path = path + self.path = URL.fileSystemRepresentation! self.storage = storage! self.sites = self.storage.keys.sorted() } func sites(withFilter filter: String?) -> [String] { return storage.keys.sorted().filter({ (name) in - if let filter = filter { - return name.localizedCaseInsensitiveContains(filter) + if filter == nil || filter!.isEmpty { + return true } - return true + return name.localizedCaseInsensitiveContains(filter!) }) } func hasSite(_ name: String) -> Bool { return (storage[name] != nil)