pinkBlossoms7 pinkBlossoms7 - 5 months ago 53
Swift Question

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"?

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

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download