【发布时间】:2020-05-03 19:27:09
【问题描述】:
我的结构由字符串和一组练习组成。用户输入他们的练习,这些值会使用核心数据保存到设备中。这些值显示在 UITableview 中。我在 UITableview 中添加了一个按钮,以便可以编辑用户输入的详细信息。我的问题是我不知道如何访问用户输入的特定文本以使他们能够对其进行编辑。
我的数组:
var contacts = [Contact]()
结构:
//Structure
struct Contact {
var id:String = "Contact - \(UUID())"
var fullname: String
var exercises : [Exercise]
}
我的运动课
class Exercise : NSObject , NSSecureCoding{
static var supportsSecureCoding: Bool = true
var excerciseName: String
var excerciseReps: String
var excerciseSets: String
var excerciseWeights: String
init(Name : String, Reps : String, Sets : String, Weights : String) {
excerciseName = Name
excerciseReps = Reps
excerciseSets = Sets
excerciseWeights = Weights
}
func encode(with aCoder: NSCoder) {
aCoder.encode(excerciseName, forKey: "excerciseName")
aCoder.encode(excerciseReps, forKey: "excerciseReps")
aCoder.encode(excerciseSets, forKey: "excerciseSets")
aCoder.encode(excerciseWeights, forKey: "excerciseWeights")
}
required convenience init?(coder aDecoder: NSCoder) {
let excerciseName = aDecoder.decodeObject(forKey: "excerciseName") as! String
let excerciseReps = aDecoder.decodeObject(forKey: "excerciseReps") as! String
let excerciseSets = aDecoder.decodeObject(forKey: "excerciseSets") as! String
let excerciseWeights = aDecoder.decodeObject(forKey: "excerciseWeights") as! String
self.init(Name: excerciseName, Reps: excerciseReps, Sets: excerciseSets, Weights: excerciseWeights)
}
}
我用来尝试访问用户输入的特定练习的代码是
print(self.contacts[indexPath.section].exercises)
但是,这将打印图像中看到的以下值,而不是用户输入的实际文本。如何访问用户输入的实际文本?
【问题讨论】:
标签: arrays swift class core-data struct