0

Suppose I have a label that is a NSTextField. I know I can access the value of that label by:

@IBOutlet weak var label: NSTextField!

let labelValue = label.stringValue

And then I can use that variable accordingly.

The same is easily said for an NSImage:

@IBOutlet weak var productImageView: NSImageView!

let img = productImageView.image

My question is how do I grab the value of a WebView. I am unsure which property allows me to use a WebView.

@IBOutlet weak var videoTemp: WebView!

let videoPassed = videoTemp //how do I access this videoTemp's value much like .stringValue and .image

I am trying to load dynamic video URL's to Youtube videos when I click on a collection view item. The line that I have commented in my setupAppVideo method is where my fatal error occurs:

"fatal error: unexpectedly found nil while unwrapping an Optional value"

but when I print out the url and request variables their are no nil values and all of them are the correct links in the console.

import Cocoa
import WebKit

class test1: NSCollectionViewItem {

@IBOutlet weak var label: NSTextField!
@IBOutlet weak var label2: NSTextField!
@IBOutlet weak var productImageView: NSImageView!
@IBOutlet weak var videoTemp: WKWebView!

var buildProduct: ProductModel? {

    didSet{

        label.stringValue = (buildProduct?.product_name)!
        label2.stringValue = (buildProduct?.product_price)!
        setupAppIconImage()
        setupAppVideo()

    }
}


override func viewDidLoad() {

    super.viewDidLoad()

}


func setupAppIconImage() {

    if let appIconImageURL = buildProduct?.product_image {
        let url = NSURL(string: appIconImageURL)

        URLSession.shared.dataTask(with: url! as URL,completionHandler:{(data, response, error) in

            if error != nil {
                print(error)
                return
            }

            DispatchQueue.main.async(){
            self.productImageView.image = NSImage(data: data!)
            }

        }).resume()

    }

}

func setupAppVideo(){


    if let appVideoURL = buildProduct?.product_video{

        let url = NSURL(string: appVideoURL)

        print(url)


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

        print(request)


        //self.videoTemp.load(request as URLRequest)


    }
}

}
Joe
  • 8,868
  • 8
  • 37
  • 59
  • Possible duplicate of [Get HTML from WKWebview in Swift](http://stackoverflow.com/questions/34751860/get-html-from-wkwebview-in-swift) – FelixSFD Oct 12 '16 at 22:31
  • No I don't think so. I have URL's to Youtube videos stored in a database that I have already pulled in via JSON and I am trying to pass them from one view to another. I have a method to setup my videos but when I try to access the values I am unsure which property of WebView is necessary to access them much like .stringValue can access a string and .image can access an image. – Nick Balistreri Oct 12 '16 at 22:35

0 Answers0