WWDC23 SALE: Save 50% on all my Swift books and bundles! >>

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

   

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! :-)

   

Save 50% in my WWDC23 sale.

SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.