Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
16.2k views
in Technique[技术] by (71.8m points)

ios - 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)
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...