Skip to content

Instantly share code, notes, and snippets.

@tsarikovskiy
Created October 4, 2018 10:08
Show Gist options
  • Select an option

  • Save tsarikovskiy/3c4b0c3391b3d307d7c7d6e8693f1a01 to your computer and use it in GitHub Desktop.

Select an option

Save tsarikovskiy/3c4b0c3391b3d307d7c7d6e8693f1a01 to your computer and use it in GitHub Desktop.
import SwiftyJSON
class JsonTestFileHandler {
enum FilePath: String {
case funnelSettings = "Settings.json"
}
static func writeTo(file filePath: FilePath, json: JSON) {
let currentFilePathArray = #file.split(separator: "/")
.map { String($0) }
.dropLast()
let funnelPath = currentFilePathArray.joined(separator: "/") + "/" + filePath.rawValue
do {
let fileURL = URL(fileURLWithPath: funnelPath)
try json.description.write(to: fileURL, atomically: false, encoding: .utf8)
} catch {
print("error:", error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment