0

I have tried to make my own currency converter from USD to SEK With the import taxes rates to Sweden but I have no clue how to take a value from a website. I have tried to find it on my own but I can't really find anything so I´m hopping anyone here could help me with this? This is how far I have built the app. I want to use this link http://www.valutaomvandling.se/usd-sek-1.html to take innformation from the code down below is the ViewController and is essentially use less but its there just to show. I only know how to go in to a website through a code like this But i don't know how to take information from a website thats where you come in hope you understand what I mean and I would be really grateful for any help.

let rect = CGRectMake(0, 20, 320, 460)
    let webView = UIWebView(frame: rect)

    let url = NSURL(string: "https://www.apple.com”)
    let request = NSURLRequest(URL: url!)

    webView.loadRequest(request)
    self.view.addSubview(webView)

import UIKit

class ImportSkattViewController: UIViewController {

    @IBOutlet weak var textfield: UITextField!
    @IBOutlet weak var svar: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()
        textfield.keyboardType = UIKeyboardType.DecimalPad

        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
        view.addGestureRecognizer(tap)

        // Do any additional setup after loading the view.
    }

    func dismissKeyboard() {
        //Causes the view (or one of its embedded text fields) to resign the first responder status.
        view.endEditing(true)

        if textfield.text == ""{
        }
        else{
            let nf = NSNumberFormatter()

            let atext2 = nf.numberFromString(textfield.text!)
            let skatt = 1.25
            let CurencyValue = 0

            let result = Float(atext2!) * Float(skatt) * Float(CurencyValue)
            svar.text = ("\(result)")

        }






    }




    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
Kevin
  • 365
  • 1
  • 3
  • 9
  • The question is about getting a value from a website, but the code you are showing is for the view controller and unrelated to your actual problem. – Abizern Mar 12 '16 at 11:45
  • I think [this SO question](http://stackoverflow.com/questions/24016142/how-to-make-an-http-request-in-swift) should get you started on making a call to a URL. To give you a more specific answer you should give us more details about the "website" you want to call (REST? SOAP? etc.) – Heyfara Mar 12 '16 at 13:39
  • Hi I have tried to be more specific now hope you se the problem and that you could help me @Heyfara – Kevin Mar 12 '16 at 14:16

1 Answers1

0

The problem is that you (probably) cannot use the website you gave. I don't speak/read Swedish (judging by the .se website^^), so maybe they say they have an API somewhere.

Anyway, you have to use an API to be able to get a response in a usable format (JSON for example). If you make a call to the given website, you will get an HTML response which is not really easy to extract useful data from (in your case).

You will find some APIs listed here). Fixer.io seems really simple to use. It just gives you the rates, but it is fairly easy to then convert any amount by a simple calculation.

Here you can find some code to make an HTTP call and parse the JSON response. With it you can call the Fixer.io API, get your change rates, and make all the calculations you want.

I am sorry I cannot test anything right now, but you should have everything you need with the provided links ;)

Hope it helps.

Community
  • 1
  • 1
Heyfara
  • 511
  • 3
  • 21