Created
September 24, 2017 13:54
-
-
Save barbaramartina/3b4e04aa396142d6312a839d793f7922 to your computer and use it in GitHub Desktop.
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
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