NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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


Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.