LAST CHANCE: Save 50% on all my Swift books and bundles! >>

SOLVED: Project7: How to calculate all expenses?

Forums > 100 Days of SwiftUI

Hi everyone, I would like to learn How to calculate all expenses through create text in same section or separate to read total amount. (just for more practice)

Thanks in advance


Hi. Well depending on how you implement different parts of that project you can just simply create property for total amount and use it where necessary.

 private var totalAmount: Double {
        expenses.items.reduce(0.0) { partialResult, item in
            partialResult + item.amount
            // also can be expressed as { $0 + $1.amount }


Thanks @ygeras


Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.