Skip to content

Instantly share code, notes, and snippets.

@sp71
sp71 / FileManager.swift
Created Mar 11, 2021
Format JSON into Label
View FileManager.swift
import UIKit
class FileManager {
static func decodeJSON<T: Decodable>(fileName: String?, subdirectory: String?) -> T? {
guard let filename = fileName else { return nil }
if filename.isEmpty { return nil }
let decoder = JSONDecoder()
guard
let url = Bundle.main.url(forResource: filename, withExtension: "json", subdirectory: subdirectory),
let data = try? Data(contentsOf: url),