Skip to content

Commit 4f1e1a8

Browse files
author
Clément Le Provost
committed
Fix file path construction
It seems that string interpolation with implicitly unwrapped optional doesn’t unwrap the optionals any longer… :/ Using `URL.appendingPathComponent()` is clearer and more robust anyway.
1 parent a4cb713 commit 4f1e1a8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Source/Offline/MirroredIndex.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ import Foundation
305305

306306
// Create temporary directory.
307307
do {
308-
tmpDir = NSTemporaryDirectory() + "/algolia/" + UUID().uuidString
308+
tmpDir = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("algolia").appendingPathComponent(UUID().uuidString).path
309309
try FileManager.default.createDirectory(atPath: tmpDir, withIntermediateDirectories: true, attributes: nil)
310310
} catch _ {
311311
NSLog("ERROR: Could not create temporary directory '%@'", tmpDir)
@@ -326,7 +326,7 @@ import Foundation
326326
assert(json != nil)
327327
// Write results to disk.
328328
let data = try JSONSerialization.data(withJSONObject: json!, options: [])
329-
self.settingsFilePath = "\(self.tmpDir)/settings.json"
329+
self.settingsFilePath = URL(fileURLWithPath: self.tmpDir).appendingPathComponent("settings.json").path
330330
try data.write(to: URL(fileURLWithPath: self.settingsFilePath), options: [])
331331
} catch let e {
332332
self.syncError = e
@@ -390,7 +390,7 @@ import Foundation
390390

391391
// Write results to disk.
392392
let data = try JSONSerialization.data(withJSONObject: json!, options: [])
393-
let objectFilePath = "\(self.tmpDir)/\(currentObjectFileIndex).json"
393+
let objectFilePath = URL(fileURLWithPath: self.tmpDir).appendingPathComponent("\(currentObjectFileIndex).json").path
394394
self.objectsFilePaths.append(objectFilePath)
395395
try data.write(to: URL(fileURLWithPath: objectFilePath), options: [])
396396

0 commit comments

Comments
 (0)