'sum nested data with swift
I am trying to sum nested data without success. This is my data:
{
"BON_PK" = 34;
"BON_EXTRA" = "100.00";
Line = ({ "LIG_PRICE" = "40.80";},
{ "LIG_PRICE" = "40.80";})
},
{
"BON_PK" = 35;
"BON_EXTRA" = "10.00";
Line = ({"LIG_PRICE" = "40.80";},
{"LIG_PRICE" = "40.80";})})
This is what I tried:
vPrice = vArr.map {$0?.Line!.map {(($0.LIG_PRICE as NSString).floatValue)}}.reduce(0, +)
This one is working but not the nested one:
vDelTotal = vArrBon.map { ($0?.BON_EXTRA!.toFloat)! }.reduce(0, +)
I created a 'toFloat' Function that is not working with the nested one. I have this error message:
Cannot convert value of type '[Float]?' to closure result type 'Float'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
