-1

I try to add address in several ways, but it's not working all the time. Anybody know the right code?

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var Dziennik: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Simon Walachowski
  • 131
  • 1
  • 1
  • 9
  • Please post your code as text, not as an image. – rmaddy Oct 26 '16 at 18:36
  • 1
    The error is quite clear. Use the correct variable name. – rmaddy Oct 26 '16 at 18:37
  • I'm new in Swift, could you tell me what should i put there? – Simon Walachowski Oct 26 '16 at 18:41
  • Look at the code you posted. What's the actual name of the variable for your `UIWebView` outlet? Use that name instead of `webView`. – rmaddy Oct 26 '16 at 18:42
  • Ok, I did what you said, but I still have issues. Can you help me to write this code? I did some changes, but still a lot of errors. I really would appreciate your help let myURL = NSURL(string: “http://www.link.com”); let myURLRequest:NSURLRequest = NSURLRequest(URL: myURL!); myWebView.loadRequest(myURLRequest); – Simon Walachowski Oct 26 '16 at 19:10

2 Answers2

0
let url = URL (string: "http://google.com")       
let requestObj = URLRequest(URL: url!);
Dziennik.loadRequest(requestObj)
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sameh Salama
  • 765
  • 1
  • 7
  • 17
  • Thank you for respond, I did it, but still there are errors. Can You tell me how to do it properly? My goal is to make Webviewer to open website. – Simon Walachowski Oct 26 '16 at 19:24
  • i understand that you want to open a url in a webview, but what error you get after you replaces the webview with your property name Dzeiinik ? – Sameh Salama Oct 26 '16 at 19:28
  • Too much. I think I'm doing it wrong. But I can't find on the web any explanation how it works. Webviewer is on the second view controller. I want it to open websites. If you could tell me what is the formula I would be grateful. – Simon Walachowski Oct 26 '16 at 19:30
  • There are errors for the rest of code. Example: 'NSURLRequest' is not simplicity convertible to 'URLREquest'; did you mean to use 'as' to explicitly convert? – Simon Walachowski Oct 26 '16 at 19:33
  • i edited my answer, please check and send me your feedback – Sameh Salama Oct 26 '16 at 19:38
  • sorry for the bad alignment, i'm sending from mobile:) – Sameh Salama Oct 26 '16 at 19:39
  • now it says: " NSURLRequest is not implicitly convertible to URLRequest did you mean to use 'as' to explicitly convert? " – Simon Walachowski Oct 26 '16 at 19:45
  • answer edited again, sorry for that, i'm not in front of my computer at the moment – Sameh Salama Oct 26 '16 at 19:47
  • Thank you, everything seems to be ok, but after building it says: Thread 1: EXC_BAD_INSTRUCTION – Simon Walachowski Oct 26 '16 at 19:51
  • @SimonWalachowski can you please paste your code? it seems like you don't know how to trace errors, it seems like something else is causing this error – Sameh Salama Oct 26 '16 at 19:58
  • `import UIKit` `class ViewController: UIViewController {` `@IBOutlet weak var Dziennik: UIWebView!` `override func viewDidLoad() {` `super.viewDidLoad()` ` let url = URL (string: "http://google.com")` ` let requestObj = URLRequest(url: url!);` `Dziennik.loadRequest(requestObj)` ` }` ` override func didReceiveMemoryWarning() {` `super.didReceiveMemoryWarning()` `// Dispose of any resources that can be recreated.` ` }` `}` – Simon Walachowski Oct 26 '16 at 20:01
  • Ok, so I don't know what's the point. Anyway, thank you very much. – Simon Walachowski Oct 26 '16 at 20:07
  • i apologize for not being able to trace the error with you – Sameh Salama Oct 26 '16 at 20:33
  • If you know how to do this (implement an answer to project in question) it would be awesome and that's what I need. [http://stackoverflow.com/questions/33276020/xcode-open-url-in-second-view-controller-based-on-button-pressed-in-first-view-c] – Simon Walachowski Oct 26 '16 at 20:48
  • sure, please upload your project and send me link – Sameh Salama Oct 26 '16 at 20:51
  • I mean, in this question you have demo project. And in answer there is solution. If you could do this for me and send this demo fixed it would be great. – Simon Walachowski Oct 26 '16 at 20:55
  • sure, please allow me sometime, once i finish i'll get back to you with a link, i'll work on it now – Sameh Salama Oct 26 '16 at 20:57
  • there you go https://dl.dropboxusercontent.com/u/100318614/Demo-Swift.zip , make sure to check ReadMe.swift file – Sameh Salama Oct 26 '16 at 21:59
  • Oh, it's working! You're awesome! Thank you very much. Do you have some tip how i could understand this code? Where should I search? @Sameh Oh you left me instructions! Thank you! If I could give You feedback or sth tell me, I'll do for sure! – Simon Walachowski Oct 28 '16 at 18:43
  • I have issues right now, because I want to add new open URL button and it's not working. Says "bad instruction" and I have no clue what's the point – Simon Walachowski Oct 28 '16 at 19:51
0

Just change this:

webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))

for this:

Dziennik.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))

The issue is the name of the property.

James Zaghini
  • 3,895
  • 4
  • 45
  • 61
desgs1990
  • 1
  • 2
  • I changed for this: `let url = URL (string: "http://google.com")` `let requestObj = URLRequest(url: url!); Dziennik.loadRequest(requestObj)` but it's still now working. (error: "Thread 1: EXC_BAD_INSTRUCTION") – Simon Walachowski Oct 26 '16 at 20:12