1

I would like to create some formatted text using HTML in my OS X program. I am programing in swift. I created a web view and set up a simple test.

import Cocoa
import RealmSwift
import WebKit

class invociegenerator: NSViewController {
@IBOutlet var InvoiceView: WebView!

override func viewDidLoad() {
    super.viewDidLoad()
    var htmlString:String! = "<br /><h2>Hello World!!</h2>"
    InvoiceView.loadHTMLString(htmlString, baseURL: nil)
        // Do view setup here.
}

}

I receive an error saying "WebView does not have a member named 'LoadHTMLString'" I must be missing something, is it possible to load from a string in an OS X program? There are plenty of tutorials online but the all focus on iOS.

1 Answer 1

5

"loadHTMLString" is a method on a WebFrame object not WebView. However, Webview does have a method that returns the mainFrame for the webview. So you could just call mainFrame on the webview like this.

InvoiceView.mainFrame.loadHTMLString(htmlString, baseURL: nil)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.