|
Hi All, Here is my solution to day 19, there were two things I was trying to do but I couldnt crack it... Any help would be appreciated Firstly, changing the currency on the 'To' changes the currency symble fine, but not on the From field. (It just stays as £) Secondly instead on hardcoding the conversion rates in to the calculation I wanted so store them in a datadictionary - something like this let convertFromRates = ["GBP": 1, "USD" : 0.81, "EUR": 0.54, "INR" :0.01] But Im not sure if this is possible? Thanks!
|
|
Greenis is asking about dictionaries:
Sure! It's possible, and I think you did it. Paste this code into Playgrounds. (Please tell us you're using Playgrounds, yes?)
Looking for Yen returns Iterating over Dictionary ValuesHere's a snip to loop over dictionary values. Paste into Playgrounds.
Reduce your CodeVery clever looking to dictionaries for this solution! Nice! You'll clean up lots of ugly, hard-to-maintain code.
Variable NameI changed the dictionary name to To me, it might make more sense in context when I'm thumbing through a Excellent questions! Keep coding! |
|
Wow! Thanks for your detailed reply :) Can your exchangeRateFor be bound to a picker? I will play with what you suggest this evening Thanks! |
|
More questions from @greenis
Do you want the answer? or do you want to learn? I provided you with code to iterate over the dictionary. How might you extract those results into a computed Try it out in See-> Dictionary Keys |
|
Great thanks! I have cracked it - its much neater now
Looking forward to the next challenge! |
|
Well done! Here are a couple of pointers. Pointer #1
When you compute a
Pointer #2
Here you're building a number of Try this:
|
|
Thanks for tips here, very helpful :) I tried binding exchangeRateFor directly to the picker just looking to the .keys but couldnt get it to work, I never thought to create a new array with just these! Thanks for the tips, I really appreciate it. I have just been coding vb.net applications for the last several years at work and getting very bored of coding, swift has get me excited about it again! |
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 February 9th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.