我可以从现有的pList中检索数据。
然后,我需要将一个对象附加到已检索的数据中。 删除pList中的数据并保存我创建的新数据
class PracAddPartVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var filePath: String?
var dataRetrieved: [[String: String]] = []
var listOfValves = [ValveStruct]()
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
filePath = Bundle.main.path(forResource: "RecentValve", ofType: "plist")
dataRetrieved = NSArray(contentsOfFile: filePath!) as! [[String: String]]
for eachDataItem in dataRetrieved {
let singleResult = ValveStruct(pn: eachDataItem["pn"] ?? "", type: eachDataItem["type"] ?? "", material: eachDataItem["material"] ?? "", manufacturer: eachDataItem["manufacturer"] ?? "")
listOfValves.append(singleResult)
print(listOfValves)
}
}
当我按下一个按钮时。 我想将新条目添加到位置0的数组中。
然后,我将需要删除pList中的现有数据并保存我创建的新数据。
@IBAction func addNewRecentValve(_ sender: Any) {
let newToAdd = ValveStruct(pn: "AB245245", type: "Valve", material: "Steel", manufacturer: "Company")
listOfValves.insert(newToAdd, at: 0)
}
有人可以帮忙吗?