How to sum NSNumber array in Swift? I'm getting this error when I use .reduce. any other way to sum the NSNumber array?
Cannot invoke 'reduce' with an argument list of type '(Int, _)
var record = [Record]()
var incomeFilter: [Record] = []
let formatter = NumberFormatter()
formatter.numberStyle = .currencyAccounting
formatter.currencySymbol = "¥"
formatter.maximumFractionDigits = 2
formatter.minimumFractionDigits = 2
incomeFilter = record.filter { $0.recordtype!.contains("Income") && $0.createdAt! == recordItem.createdAt!}
let incomeSumArray = incomeFilter.map{formatter.number(from: $0.amount!) ?? 0.00}.reduce(0, +)
//Cannot invoke 'reduce' with an argument list of type '(Int, _)
print(incomeSumArray)
//result without .reduce
//[9.99, 6.58, 7777.77]
Doublevalues and then use the number formatter and I explained the error message in my answer yesterdaydoublefirst, the number which above 1,000 will get nil. The separator break the string to double conversion routine. @vadian