Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When loading a local resource file in a mac app

let urlpath = NSBundle.mainBundle().pathForResource("myResource", ofType: "html");

Converting the resource path to a string for NSURL always returns nil

    println("resource path = (urlpath)") <---resource logged ok

    web.frameLoadDelegate = self;
    let requesturl = NSURL(string: urlpath!)

   println("URL String  = (requesturl)"),<---- returns nil

    let request = NSURLRequest(URL: requesturl!)
    web.mainFrame.loadRequest(request)

Which presumably is why im getting the error found nil while unwrapping an Optional value What am I missing here to correctly convert the pathForResource to a string?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

if let myFileUrl = NSBundle.mainBundle().URLForResource("yourFile", withExtension: "html"){
            // do whatever with your url
} 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...