Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import Foundation
  2.  
  3. // Extension on PropertyListSerialization to read an array from a property list file
  4. extension PropertyListSerialization {
  5.  
  6. // Takes the name of the PLIST file to be read. Name must be provided without extension.
  7. // returns an optional array if the file can be opened and parsed properly.
  8. // - Parameters:
  9. // - named String with the filename. No extension .plist needed
  10. static func arrayFromPlist(named name: String) -> [Any]? {
  11.  
  12. if let path = Bundle.main.url(forResource: name, withExtension: "plist"),
  13. let data = try? Data(contentsOf: path) {
  14. if let content = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [Any] {
  15. return content
  16. }
  17. }
  18. return nil
  19. }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement