Hello:
I am fetching records from CoreData in which there is an item called QValue. qValue is defined as a String but it has a number.
qValue has different values (1000,1450, 1830, etc.)
Each time the user calls for a record it returns a qValue in the data set.
I want to Sum all the qValues returned in a session.
I have tried many different ways but without success: for example (The error here is "Ambiguous reference to member '+' ")
if let record = item.value(forKey: "qValue") as? String {
qValueItem.append(record)
groupScoreLabel.stringValue = qValueItem
print ("qValue is \(qValueItem)")
}
if (oneRadioButton.state == NSControl.StateValue(rawValue: 1))
&& distractor1 == answerItem {
let arr = [qValueItem]
let totalSum = arr.reduce(0, +) // Ambiguous reference to member '+'
print("totalSum \(totalSum)")
I want an increasing value with each record call which will be the "totalSum"
Any help with implementing will be appreciated.
OK, add a test before line 23:
print ("qValueNumbers before radiobuttons", qValueNumbers)
Tell what it gives
But most likely, the print you get is the one line 67.
Here, totalSum has not been recomputed.
So, once again, it is likely that all the tests fail
if oneRadioButton.state == .on && distractor1 == answerItem {
and the others as well
-> You need to understand why.
Add just before line 67:
let totalSum = qValueNumbers.reduce(0, +)
That should give you 7700
Note: I don't understand what those tests as
if oneRadioButton.state == .on && distractor1 == answerItem {
are used for: you do the same thing in all the cases !