Giter VIP home page Giter VIP logo

ios-afternoon-project-swift-fundamentals-iii's Introduction

Swift Fundamentals III Afternoon Project

Create a Currency Convert app that can convert from US dollars (USD) to Canadian dollars (CAD) and Mexican Pesos (MXN).

Get the currency conversion value from Google:

On August 7th, 2019 they were:

$1 USD to $1.33 CAD
$1 USD to $19.70 MXN

Currency Converter App

Currency App Converter

Add the Conversion Logic

In ViewController.swift:

  1. Create a currency type enum above the class and below the import statements.

    enum Currency {
        case cad
        case mxn
    }
  2. Create a property named currency of type Currency. This will store the current currency type we'll be converting to. Set an initial value of .cad.

  3. In the cadButtonTapped action:

    • Toggle this button's isSelected state
    • Toggle the mxn button's isSelected state
    • Check this button's state, and if true:
      • set the currency property to .cad
      • Display the currency in the toCurrencyLabel (so have it say "Currency (CAD)")
  4. In the mxnButtonTapped action:

    • Toggle this button's isSelected state
    • Toggle the cad button's isSelected state
    • Check this button's state, and if true:
      • set the currency property to .mxn
      • Display the currency in the toCurrencyLabel (so have it say "Currency (MXN)")
  5. Create a helper method to calculate the currency based on the Currency using the method signature:

    func convert(_ dollars: Double) -> Double {
    }
  6. In the above method:

    • Check the value of currency to see whether you should convert to CAD or MXN
    • Perform the conversion with the dollars passed into this method
    • Return the converted value
  7. In the convertButtonTapped() action method:

    • use a guard let to get user input
    • convert the dollar amount to the expected currency (hint, you'll want to call the convert method you created in step 5)
    • Update the toCurrencyTextField.text property with the converted currency value

Go Further (Optional)

  1. Customize the output display using a NumberFormatter

    var currencyFormatter: NumberFormatter = {
        let formatter = NumberFormatter()
        formatter.numberStyle = .currency
        return formatter
    }()
  2. Use the string(from:) method to convert from a number to a String for display

ios-afternoon-project-swift-fundamentals-iii's People

Contributors

jcgohlke avatar paulsolt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.