You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When initialized with an empty string using the fileURLWithPath, NSURL returns nil.
Unfortunately, the initializer is not marked as failable in Swift, leading to runtime crashes.
Consider the code below:
import Foundation
let url1 = URL( fileURLWithPath: "" )
let url2 = NSURL( fileURLWithPath: "" )
print( url1 )
print( url2 )
Here, both url1 and url2 are non-optional.
However, url2 will still be nil at runtime, leading to a crash in the last line, when trying to use the value.
Attached is a sample project demonstrating the issue.
Description
When initialized with an empty string using the
fileURLWithPath
, NSURL returns nil.Unfortunately, the initializer is not marked as failable in Swift, leading to runtime crashes.
Consider the code below:
Here, both
url1
andurl2
are non-optional.However,
url2
will still be nil at runtime, leading to a crash in the last line, when trying to use the value.Attached is a sample project demonstrating the issue.
Files
URL.zip
The text was updated successfully, but these errors were encountered: