pinkBlossoms7
pinkBlossoms7

Reputation: 65

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:

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

Upvotes: 1

Views: 650

Answers (1)

rmaddy
rmaddy

Reputation: 318814

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.

Upvotes: 1

Related Questions