Skip to content

Instantly share code, notes, and snippets.

@arslanbilal
Last active December 14, 2018 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arslanbilal/1203831e2959b29d1e460a504836858d to your computer and use it in GitHub Desktop.
Save arslanbilal/1203831e2959b29d1e460a504836858d to your computer and use it in GitHub Desktop.
PropertyListDecoder with Codable
//
// PlistDecoder.swift
// Bilal Arslan
//
// Created by BILAL ARSLAN on 14.12.2018.
// Copyright © 2018 BILAL ARSLAN. All rights reserved.
//
import Foundation
final class PlistDecoder {
class func decode<T: Decodable>(type: T.Type, with url: URL) -> [T] {
var objects: [T] = []
do {
let data = try Data(contentsOf: url)
let decoder = PropertyListDecoder()
objects = try decoder.decode([T].self, from: data)
} catch {
Log.assertFailure("Cannot create models from: \(url.lastPathComponent)")
}
return objects
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment