Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement