     
     public func loadURL(url: NSURL) {
         let request = NSURLRequest(URL: url)
-        self.webView?.loadRequest(request)
+        self.webView.loadRequest(request)
     }
 }
 

    }
    
    public func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        return true
    }
    
    public func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
        println("WebViewController Error: \(error)")
    }
}


import Foundation


public class WebViewController: UIViewController {
    
    private(set) public var url: NSURL?
    var shouldAnimateHistoryChange = true
    var isSharingWebView = false
    
    lazy var placeholderImageView: UIImageView = {
        let imageView = UIImageView(frame: self.view.bounds)
        self.view.insertSubview(imageView, atIndex: 0)
        return imageView
    }()
    
    private(set) public lazy var webView: UIWebView = {
        let webView = UIWebView(frame: self.view.bounds)
        webView.delegate = self
        self.view.addSubview(webView)
        return webView
    }()
    
    var isAppearingFromPop: Bool {
        return !isMovingFromParentViewController() && webView.superview != view
    }
    
    convenience init(webView: UIWebView) {
        self.init(nibName: nil, bundle: nil)
        self.webView = webView
        self.isSharingWebView = true
    }
    
    deinit {
        if webView.delegate === self {
            webView.delegate = nil
        }
    }
    
    override public func viewDidLoad() {
        super.viewDidLoad()
        
        if isSharingWebView {
            containWebView()
        }
    }
    
    public override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        if isAppearingFromPop {
            popState()
            containWebView()
        }
    }
    
    func containWebView() {
        webView.delegate = self
        webView.removeFromSuperview()
        webView.frame = view.bounds
        webView.scrollView.contentInset = UIEdgeInsetsZero
        webView.hidden = false // todo: wait to unhide untill load completes
        view.addSubview(webView)
    }
}

