How to fetch .plist / property list content and show in swift 4.2
Asked
Active
Viewed 162 times
-3
-
Show in which way? – user28434'mstep Jul 19 '19 at 11:20
-
Possible duplicate of [How do I get a plist as a Dictionary in Swift?](https://stackoverflow.com/questions/24045570/how-do-i-get-a-plist-as-a-dictionary-in-swift) – guru Jul 19 '19 at 11:28
1 Answers
0
// 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)")
}

NSurajit
- 413
- 4
- 10