-3

I am relatively very new to swift. Could you please help me how to load a webview in an ios app based on swift. Basically I want to load the contents of an external URL in an ios app.

Can anyone please help?

Jab2Tech
  • 165
  • 1
  • 14
  • 1
    You can read this question http://stackoverflow.com/questions/25597092/how-to-load-url-in-uiwebview-in-swift – Cong Tran Dec 30 '15 at 04:42

2 Answers2

0
override func viewDidLoad() {
super.viewDidLoad()
let webV:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
webV.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")))
webV.delegate = self;
self.view.addSubview(webV)}

and if you want use delegate function

func webView(webView: UIWebView!, didFailLoadWithError error: NSError!) {
    print("Webview fail with error \(error)");
}
func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
    return true;
}
func webViewDidStartLoad(webView: UIWebView!) {
    print("Webview started Loading")
}
func webViewDidFinishLoad(webView: UIWebView!) {
    print("Webview did finish load")
Piyush
  • 1,534
  • 12
  • 32
0

Before asking your questions research what you're looking, because this question has been answered on many forums.

In the viewDidLoad() add the following code. Make sure to connect the WebView to the View and to connect the outlet.

   let url = NSURL (string: "https://www.google.com");
    let requestObj = NSURLRequest(URL: url!);
    myWebView.loadRequest(requestObj);
}
Katz
  • 826
  • 3
  • 19
  • 40