6 Replies
      Latest reply: Oct 20, 2016 1:30 AM by eskimo RSS
      Mats Van Molle Level 1 Level 1 (0 points)

        hello,

         

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

         

        here is my code

         

        pleas help me.

        tnx

        • Re: webView xcode 8
          Mats Van Molle Level 1 Level 1 (0 points)

          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?) {

                  /

                  /

              }

              */

          }

            • Re: webView xcode 8
              rsharp Level 3 Level 3 (145 points)

              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)
                 ...
              }
              
            • Re: webView xcode 8
              Jquilliam Level 1 Level 1 (0 points)

              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

                    

                  }

                    

                  }

                • Re: webView xcode 8
                  eskimo Apple Staff Apple Staff (6,490 points)

                  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"