Since NSDictionary.init?(contentsOfFile path: String) is deprecated from iOS 11, so this is a simple demo shows how to replace it with new APIs.
Created
January 26, 2018 00:54
-
-
Save Lancewer/54f49a1d29adc916f992dd6641762c10 to your computer and use it in GitHub Desktop.
[ConvertPlistToDictionary] new API that replace NSDictionary.init?(contentsOfFile path: String) #Dictionary #plist #contentOfFile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class func getCategories() -> (categoryDict:[String:Any], level1CateArray:[String]) { | |
var categoriesDict:[String:Any] = [:] | |
var level1Categories:[String] = [] | |
if let path = Bundle.main.path(forResource: "Category", ofType: "plist") { | |
let rawData = try! Data(contentsOf: URL(fileURLWithPath: path)) | |
if let categoryDict = try! PropertyListSerialization.propertyList(from: rawData, format: nil) as? [String:Any] { | |
categoriesDict = categoryDict | |
for k in categoryDict.keys { | |
level1Categories.append(k) | |
} | |
} | |
} | |
return (categoriesDict, level1Categories) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment