【发布时间】:2018-12-18 05:31:18
【问题描述】:
我已经在互联网上搜索过,但我仍然不明白如何将值插入到变量中。我试图将一个值插入到一个变量中,这样我就可以将它附加到一个数组中,然后将它放在一个 tableviewcell 中。
我了解单元格的工作原理,我只是想知道如何将数据插入此变量
这是我的结构的代码
import Foundation
import UIKit
enum issueType: String {
case major = "Major", blocker = "Blocker", minor = "Minor"
}
struct Issue {
var id: String
var tester: String
var type: issueType
var title: String
var appName: String
var desc: String
var date: Date
var bgColor: UIColor?
init(){
id = ""
tester = ""
type = .minor
title = ""
appName = ""
desc = ""
date = Date()
bgColor = UIColor.main()
}
init(item: [String:Any]){
self.init()
id = item["id"] as? String ?? ""
tester = item["tester"] as? String ?? ""
title = item["title"] as? String ?? ""
appName = item["appName"] as? String ?? ""
desc = item["desc"] as? String ?? ""
if type == .major {
bgColor = UIColor.main()
}
else if type == .blocker {
bgColor = UIColor.blue
}
else {
bgColor = UIColor.green
}
}
}
这是来自不同类的 superDidLoad 中变量的代码
override func viewDidLoad() {
super.viewDidLoad()
var issue1 = Issue(id: "id", tester: "tester", type: .minor, title: "title", appName: "appName", desc: "desc", date: Date())
issue1.bgColor = UIColor.main()
array.append(issue1)
}
【问题讨论】: