UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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

3      

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 }
        }
    }

2      

Thanks @ygeras

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.