【发布时间】:2020-02-14 16:14:21
【问题描述】:
我正在研究一个项目,它读取一个 plist 包含字典行,一个名为 countries 的数组包含国家,国家数组填充了我的 plist 的数据并且一切正常,现在我需要定义一个元素和用它来追加到我的数组,
这是我的国家/地区定义
struct Country : Codable {
let orFlagEmoji, destFlagEmoji, : String
private enum CointryKeys : String, CodingKey { case orFlagEmoji,destFlagEmoji }
}
var countries = [Country]()
override func viewDidLoad()
{
super.viewDidLoad()
let urlPlist = Bundle.main.url(forResource: "ListinFirstPage", withExtension: "plist")!
let data = try! Data(contentsOf: urlPlist)
do
{
countries = try PropertyListDecoder().decode([Country].self, from: data)
}
catch
{
// Handle error
print(error)
}
//The problem is in two line bottom
var test = [TableViewController.Country(orFlagEmoji: "something", destFlagEmoji: "one thing")]
countries.append(test)
}
当我添加这两行时
var test = [TableViewController.Country(orFlagEmoji: "something", destFlagEmoji: "one thing")]
countries.append(test)
它遇到了这个错误
Cannot convert value of type '[TableViewController.Country]' to expected argument type 'TableViewController.Country'
,我真的很感激任何帮助。谢谢你
【问题讨论】:
标签: ios arrays swift dictionary plist