I am working on a function that takes the total cost of all the "MP" in a value and adds it up. Here is my code for context.
typealias Spell = (name: String, cat: Category, cost: Int)
let startingSpellList: [Spell] = [
("Poison", .attack, 3),
("Bio", .attack, 26),
("Fire", .attack, 4),
("Fire 2", .attack, 20),
("Fire 3", .attack, 51),
("Ice", .attack, 5),
("Ice 2", .attack, 21),
("Ice 3", .attack, 52),
("Bolt", .attack, 6),
("Bolt 2", .attack, 22),
("Bolt 3", .attack, 53),
("Pearl", .attack, 40),
("Quake", .attack, 50),
("Break", .attack, 25),
("Doom", .attack, 35),
("Flare", .attack, 45),
("Meteor", .attack, 62),
("Ultima", .attack, 80),
Here is the function :
func totalCost(_ spells: [Spell]) -> Int {
let cost = spells.cost
let sum = cost.reduce(0, +)
return sum
}
With this code, I get the error that `"Value of type '[Spell]' (aka 'Array<(name: String, cat: Category, cost: Int)>') has no member 'cost'." How should I fix this error?