webView xcode 8

hello,


i downloaded xcode 8 and now I can't load a webView animore


here is my code


pleas help me.

tnx

Replies

here is my code


import UIKit

class website: UIViewController {

@IBOutlet var webView: UIWebView!


override func viewDidLoad() {

super.viewDidLoad()

let url = NSURL (string: "http:/

let requestObj = NSURLRequest(URL: url!); // here he givs me an eror "NSURL is not implicily convertible to "url;"did you mean tu use "as" to explicitly convert"


webView.loadRequest(requestObj)

/

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

/

}

/

/

/

override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {

/

/

}

*/

}

It looks like you've converted your project to Swift 3. Many Foundation types are now value types and have dropped the 'NS' prefix. Most (all?) of the APIs now expect to work with the newer types. If you must stick with NSURL, etc., that would require a cast (the error you are seeing).


In your example above, you can directly create new URL and URLRequest types. For example:


if let theURL = URL(string: "http://www.apple.com") {

    let theURLRequest = URLRequest(url: theURL)
   ...
}

Thank you rsharp 🙂

hi


I am a beginnng xcode / swift developer

It will help me if the code worked and let me see a copy of the complete program.

melvynfeuerman@gmail.com



Thank you


I have been trying to get this 2 line program to work using xcode 7.3 and 8.0 for weeks!!


Mel

I have a issue linking a searchbar to a webview. All I need it to do it add the searchbar input to the end of a url. cant seem to get it to work on Xcode 8. i keep recieving a "Thread 1: Breakpoint 1.1 error"


import UIKit

class SearchViewController: UIViewController, UISearchBarDelegate {


@IBOutlet weak var SearchBar: UISearchBar!

@IBOutlet weak var SearchWebview: UIWebView!

override func viewDidLoad() {

super.viewDidLoad()

let url = NSURL(string: "http:/

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

SearchWebview.loadRequest(request as URLRequest)

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

}

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {

searchBar.resignFirstResponder()

let text = SearchBar.text

let url = NSURL(string: "http:/

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

SearchWebview.loadRequest(request as URLRequest) // this is where i get the error

}

}

Your code snippet was munged, which makes it very hard to offer concrete advice. If you edit your post to fix the snippet (use the

<>
button to add a code block, and then, after you’ve made the post, go back and verify that it’s being displayed correctly), I might be able to help out more.

Some general advice:

  • Update you code to work with Swift value types (like

    URL
    and
    URLRequest
    ) rather than relying on Foundation types (
    NSURL
    and
    URLRequest
    ).
  • If you’re building a URL from parts, use

    URLComponents
    rather than string processing.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"