Skip to content

Instantly share code, notes, and snippets.

View shahdhiren's full-sized avatar

Dhiren Shah shahdhiren

View GitHub Profile
@shahdhiren
shahdhiren / swift4-plist-extract.swift
Created February 2, 2019 14:20 — forked from db42/swift4-plist-extract.swift
Swift 4 recipes: Extract data from a property list
//Property List file name = regions.plist
let pListFileURL = Bundle.main.url(forResource: "regions", withExtension: "plist", subdirectory: "")
if let pListPath = pListFileURL?.path,
let pListData = FileManager.default.contents(atPath: pListPath) {
do {
let pListObject = try PropertyListSerialization.propertyList(from: pListData, options:PropertyListSerialization.ReadOptions(), format:nil)
//Cast pListObject - If expected data type is Dictionary
guard let pListDict = pListObject as? Dictionary<String, AnyObject> else {
return
}