Reputation: 421
How to fetch .plist / property list content and show in swift 4.2
Upvotes: -3
Views: 174
Reputation: 421
// 1. Forming resource URL of property list file
// 2. getting Data from url
// 3.serializing plist data to NSObject type classess .
1.guard let plistUrl = Bundle.main.url(forResource: "Your property- list file name ", withExtension: "plist"),
2.let plistData = try? Data(contentsOf: plistUrl) else { return nil }
var plistEntries: [[String: Any]]? = nil
do {
3. plistEntries = try PropertyListSerialization.propertyList(from: plistData, options: [], format: nil) as? [[String: Any]]
} catch {
print("error reading plist")
}
for property in plistEntries {
guard let property1 = property["key-name"] as? String,
let property2 = property["key-name"] as? NSNumber
else { fatalError("Error reading data") }
print("value: \(property1)")
print("value: \(property2)")
}
Upvotes: 0