Last active
December 14, 2018 10:56
-
-
Save arslanbilal/1203831e2959b29d1e460a504836858d to your computer and use it in GitHub Desktop.
PropertyListDecoder with Codable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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