Get the sum of the values of the same label from the struct

I need to add the unappeared to the Array from this information. If there is a duplicate, the money will be summed up and then saved into one. How can I achieve this? The data may be a lot.

import UIKit

struct TestData {
let Label : String
var Money : Double
}

var SaveDate = TestData
var TestD = TestData
SaveDate.append(TestData(Label: “test1”, Money: 55))
SaveDate.append(TestData(Label: “test1”, Money: 35))
SaveDate.append(TestData(Label: “test2” , Money: 15))
SaveDate.append(TestData(Label: “test1” , Money: 10))
SaveDate.append(TestData(Label: “test3” , Money: 30))
print([{Label “test1”, Money 55}, {Label “test1”, Money 35}, {Label “test2”, Money 15},{Label “test1”, Money 10}, {Label “test3”, Money 30}])

//Result presentation
//Label1 = test1 , Money = 100
//Label2 = test2 , Money = 15
//Label3 = test3 , Money = 30


#arrays #swift

5 Likes2.05 GEEK