我想从 Plist 中读取一个带有属性(btnImage+btnTitle)的字典数组到 TableViewCell
i Want to read an Array of Dictionary with properties(btnImage+btnTitle) from Plist into TableViewCell
Created array of dictionary having buttons.
-创建了 UITableviewcell.xib 和 .swift
-创建IB
-链接IB
-链接的数据源和代表
需要帮助进一步阅读我的 plist 数据并将其显示到 tableViewCell
使用Decodable
,很简单
struct Section : Decodable {
let title, icon : String
}
如果文件在包中,将其读取为Data
并解码
let url = Bundle.main.url(forResource: "sections", withExtension: "plist")!
do {
let data = try Data(contentsOf: url)
let result = try PropertyListDecoder().decode([Section].self, from: data)
} catch { print(error) }
result
将包含 Section
项的数组
Created array of dictionary having buttons.
-创建了 UITableviewcell.xib 和 .swift -创建IB -链接IB -链接的数据源和代表 需要帮助进一步阅读我的 plist 数据并将其显示到 tableViewCell
使用Decodable
,很简单
struct Section : Decodable {
let title, icon : String
}
如果文件在包中,将其读取为Data
并解码
let url = Bundle.main.url(forResource: "sections", withExtension: "plist")!
do {
let data = try Data(contentsOf: url)
let result = try PropertyListDecoder().decode([Section].self, from: data)
} catch { print(error) }
result
将包含 Section
项的数组