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

Hacking with watchOS - Project 4 - Currency Conversion - Is the code incomplete?

Forums > Books

I think I'm overlooking something with this project. It seems a currency conversion app would multiply the exchange rate by the total amount to get the converted amount. In fact, the documentation references this:

...take a currency tuple – its symbol and rate – and format them both into a single string by multiplying the rate with how much the user asked to convert. So, if they are converting 500 USD, we’ll return something like 450 EUR.

My code, following the tutorial, does not do this. The conversion rates display, not the multiplied amounts.

I resolved this by modifying the rate method to include amount as a parameter and then complete the expected multiplication (amount * result.rate). This works as I would expect.

Am I missing something? It seems the code in the book is incomplete.

Just curious.

... now off to figure out why the values on ResultsView are duplicated every time I return from CurrenciesView...

3      

To add to my confusion regarding difference between my seemingly working code as compared to what I followed in the book...

As mentioned above, when using the code as published, every time I navigated from ResultsView to CurrenciesView and then back to ResultsView, the results were duplicated.

I needed to add fetchedCurrencies = [] before the for loop in the parse method.

As mentioned in my original post, it seems the code in the book is incomplete. But, I don't trust that assessment of mine! :-)

3      

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!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.