[英]Error: Value of type 'String' has no member 'totalAnswered'
I am using CoreData for my project and I came into this error:我正在为我的项目使用 CoreData,但我遇到了这个错误:
Error: Value of type 'String' has no member 'totalAnswered'
错误:“String”类型的值没有成员“totalAnswered”
Here is my circumstance:这是我的情况:
I have a CoreData model with the entity "Scores" and the ff.我有一个带有实体“Scores”和 ff 的 CoreData 模型。 attributes:
属性:
I am using a table to show the data above.我正在使用表格来显示上面的数据。
Here is the problem part of my code for the Cell data:这是我的单元格数据代码的问题部分:
if let date = score.datePlayed, let score = score.totalScore, let questions = score.totalAnswered {
I have no trouble saving into the entity "Scores" using the term "score" as illustrated in the code above.如上面的代码所示,我可以使用术语“分数”将其保存到实体“分数”中。 Also, I have no trouble showing the "score.datePlayed" and the "score.totalScore".
另外,我可以毫不费力地显示“score.datePlayed”和“score.totalScore”。 However, the code "score.totalAnswered" is where I am having problems.
但是,代码“score.totalAnswered”是我遇到问题的地方。 It receives the error code above.
它收到上面的错误代码。
I have tried cleaning my project but the error still persist.我尝试清理我的项目,但错误仍然存在。
What should I do to show the data of "score.totalAnswered"?我该怎么做才能显示“score.totalAnswered”的数据?
EDIT: I am using the code above to display the data using the ff.编辑:我使用上面的代码使用 ff 显示数据。 code:
代码:
cell.textLabel?.text = "Date: \(date)\nScore: \(score)/\(questions)"
Look at the 2nd let
.看第二个
let
。 You create a new variable named score
that hides the original variable named score
.您创建了一个名为
score
的新变量,该变量隐藏了名为score
的原始变量。 So the 3rd let
is trying to access the wrong score
.所以第三个
let
试图访问错误的score
。
The best solution is to use a different variable name on the 2nd let
.最好的解决方案是在第二个
let
上使用不同的变量名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.