Skip to content

Instantly share code, notes, and snippets.

@sp71
sp71 / FileManager.swift
Created March 11, 2021 11:43
Format JSON into Label
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),