Search code examples
iosswift3xcode8

Load html file to WebView from local custom folder in swift 3


I want to load html file to WebView from local custom folder - ProjectNameFolder/test/index.html.

Trying this code, but doesn't work.

mWebView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "test/index", ofType: "html")!) as URL))

EDITED

When I do without folder name, works perfectly.

mWebView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "index", ofType: "html")!) as URL))

P.S. I'm new in Swift.


Solution

  • I found solution for my problem.

    Drag and drop test folder into project folder.

    enter image description here

    enter image description here

    Here is code

    override func viewDidLoad() {
        super.viewDidLoad()     
        mWebView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "test/index", ofType: "html")!)))
    }