Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Web Browser Application Doesn't Work

I've been playing around with Xcode and made a Web Browser Application but when i type a valid URL nothing comes up. is something wrong with the syntax?

code:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    var address: String = String()



    @IBOutlet weak var webAddress: UITextField!
    @IBOutlet weak var webView: UIWebView!


    @IBAction func goPressed(sender: AnyObject) {
        webAddress.resignFirstResponder()
        loadWebPage()
    }

    @IBAction func leftPressed(sender: AnyObject) {
        webView.goBack()
    }

    @IBAction func rightPressed(sender: AnyObject) {
        webView.goForward()
    }

    @IBAction func zoomInPressed(sender: AnyObject) {
        webView.scrollView.zoomScale += 0.1
    }

    @IBAction func zoomOutPressed(sender: AnyObject) {
        webView.scrollView.zoomScale -= 0.1
    }

    func loadWebPage() {

        if webAddress.text != "" {

            address = address.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
            address = self.webAddress.text!

            if address.hasPrefix("www. ") {
                address = "http://" + address
            }else if !address.hasPrefix("http://") {

            }

            }
        let url = NSURL(string: address)
        let request = NSURLRequest(URL: url!)
        webView.loadRequest(request)

        }



    func textFieldShouldReturn(textField: UITextField) -> Bool {
         webAddress.resignFirstResponder()
        loadWebPage()
        return true

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        webAddress.delegate = self
        webView.scalesPageToFit = true
    }

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

}

Here is my IB image

alt text

feel free to copy and paste or use, I'm not really looking in to publishing or anything

wait i figured it out. in the info.plist there was some stuff i had to do and i coded the load web page function wrong i had a unneeded space and forgot an else statement