'How to add value from object in dictionary in Swift?

I have dictionary which is having objects as value, I want to retrieve value from object.

code :

 public class Student {

    public let name: String
    public let age: Double

     public init(name: String, age: Double) {
         self.name = name
         self.age = age
     }
} 

and dictionary as ["1": Student, "2" : Student ]

How can i add all the ages of student? for 13 + 12.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source