Skip to content

Instantly share code, notes, and snippets.

@barbaramartina
Created September 24, 2017 13:54
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 barbaramartina/3b4e04aa396142d6312a839d793f7922 to your computer and use it in GitHub Desktop.
Save barbaramartina/3b4e04aa396142d6312a839d793f7922 to your computer and use it in GitHub Desktop.
import Foundation
// Extension on PropertyListSerialization to read an array from a property list file
extension PropertyListSerialization {
// Takes the name of the PLIST file to be read. Name must be provided without extension.
// returns an optional array if the file can be opened and parsed properly.
// - Parameters:
// - named String with the filename. No extension .plist needed
static func arrayFromPlist(named name: String) -> [Any]? {
if let path = Bundle.main.url(forResource: name, withExtension: "plist"),
let data = try? Data(contentsOf: path) {
if let content = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [Any] {
return content
}
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment