我想将具有属性(btnImage + btnTitle)的字典数组从Plist读取到TableViewCell中

时间:2019-01-09 08:50:55

标签: arrays swift uitableview dictionary plist

Created array of dictionary having buttons.

创建的UITableviewcell.xib和.swift 创建的ib 连锁ib 链接的数据源和代理 需要进一步的帮助来读取我的plist数据并将其显示到tableViewCell

1 个答案:

答案 0 :(得分:0)

使用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个项目的数组