Crash when unwrapping an optional, but I don't see any optional?

Viewed 27

I receive several crash reports:

Bugsnag:

VC.swift:290:34
Swift runtime failure: Unexpectedly found nil while implicitly unwrapping an Optional value

Apple Crash: xcode extract

Line 290 has following code


    func showFolders(path:String, topLevel:Bool = false, absolutePath:String) {
        print(" Get folder: " + path)
                
        NetworkingService.shared.webdav.contentsOfDirectory(path: path, completionHandler: {
             some code
        })

    }

The function 'showFolders' is called by following code which avoids to send any optional value:


       let path = browser_relativePath?.absoluteString.removingPercentEncoding ?? ""
        let topLevel = NetworkingService.shared.url_connected.hostOnly.withTrailingSlash == browser_absolutePath?.absoluteString
        let absolutePath = browser_absolutePath?.path ?? ""
        self.embeddedViewController.showFolders(path:path, topLevel: topLevel, absolutePath: absolutePath)

I don't understand how this might crash by "unwrapping an optional" when there is no optional in that part of the code... But I am probably blind ;-)

Can someone help me out ?

1 Answers

The clue is it says when implicitly unwrapping… so either NetworkingService.shared or NetworkingService.shared.webdav is declared as implicitly unwrapped and is nil when you call it

Related