Search code examples
iosswiftnsurl

Why does using Nsurl request keeps telling me to rename to "init(url)"


Also trying to add the ability to detect a video and download it to the application in short a web-based app used for download any kind of video and has the ability to store it within the app

import UIKit

class ViewController: UIViewController {

    @IBOutlet var Webview: UIWebView!
    @IBOutlet var SearchBar: UISearchBar!

    override func viewDidLoad() {
       let url = NSURL(string: "https://www.google.com")
        let request = NSURLRequest(URL: url! as URL) Webview.loadRequest(request)
        SearchBar.text = "http://"
    }

    func searchBarSearchButtonClicked(searchbar: UISearchBar) {
        searchbar.resignFirstResponder()
        let text = SearchBar.text
        let url = NSURL(string: text!)
        let urlRequest:URLRequest = URLRequest(url: url! as URL)

        //  let request = NSURLRequest(URL: url! as URL)

        Webview.loadRequest(urlRequest)
    }

}

Solution

  • You need to use like this in swift

    if let url = URL(string: "https://www.google.com"){
        let requestObj = URLRequest(url: url)
        Webview.loadRequest(requestObj)
    }