Ibad Ur Rahman Ibad Ur Rahman - 3 months ago 13
HTML Question

how to load local html file to string variable in ios swift?

i want to load my local html file into a string variable. i don't know how to do it. please help me.
i found below link but it load it from online url.
Swift & UIWebView element to hide


Copy the html into your project directory and use this code :

@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {

        var htmlFile = NSBundle.mainBundle().pathForResource("MyHtmlFile", ofType: "html")
        var htmlString = try? String(contentsOfFile: htmlFile!, encoding: NSUTF8StringEncoding)
        webView.loadHTMLString(htmlString!, baseURL: nil)