简体   繁体   English

错误:“String”类型的值没有成员“totalAnswered”

[英]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:属性:

  • datePlayed播放日期
  • totalScore总得分
  • totalAnswered总回答

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.

相关问题 错误:类型字符串的值没有成员componentsSeparatedByCharactersInSet - Error: Value of type string has no member componentsSeparatedByCharactersInSet 错误:类型&#39;String&#39;的值没有成员&#39;URLByAppendingPathComponent&#39; - Error : Value of type 'String' has no member 'URLByAppendingPathComponent' “结果”类型的值 <String> &#39;没有会员&#39;错误&#39;[Alamofire,Swift 5] - Value of type 'Result<String>' has no member 'error' [Alamofire, Swift 5] 错误:实现UISearchController时类型&#39;[String]&#39;的值没有成员&#39;objectAtIndex&#39; - error: Value of type '[String]' has no member 'objectAtIndex' while implementing UISearchController &#39;string&#39; 类型的值没有成员 &#39;containsString&#39; - Value of type 'string' has no member 'containsString' 类型“ [String]”的值没有成员“ lastObject” - value of type '[String]' has no member 'lastObject' 错误:输入'String!'没有会员'视频' - Error: Type 'String!' has no member 'video' &#39;String&#39;类型的值没有成员&#39;substringToIndex&#39; - Value of type 'String' has no member 'substringToIndex' 类型&#39;String&#39;的值没有成员&#39;removeVowels&#39; - Value of type 'String' has no member 'removeVowels' &#39;String&#39; 类型的值没有成员 &#39;stringByTrimmingCharactersInSet&#39; - Value of type 'String' has no member 'stringByTrimmingCharactersInSet'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM