简体   繁体   中英

Error: Value of type 'String' has no member 'totalAnswered'

I am using CoreData for my project and I came into this error:

Error: Value of type 'String' has no member 'totalAnswered'

Here is my circumstance:

I have a CoreData model with the entity "Scores" and the ff. 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". However, the code "score.totalAnswered" is where I am having problems. 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"?

EDIT: I am using the code above to display the data using the ff. code:

cell.textLabel?.text = "Date: \(date)\nScore: \(score)/\(questions)"

Look at the 2nd let . You create a new variable named score that hides the original variable named score . So the 3rd let is trying to access the wrong score .

The best solution is to use a different variable name on the 2nd let .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM