Take the following file, named Permissions.plist
:
This is wrong:
guard let docsURL = NSURL(string: docsString) else { ... }
To create an NSURL
from a file path, use
let docsURL = NSURL(fileURLWithPath: docsString)
Conversely, you cannot use string interpolation to create a file path
from an NSURL
:
let plistString = "\(plistURL)"
Use the .path
method instead:
let plistPath = plistURL.path!
Or better, use the writeToURL()
method to write your dictionary,
then you don't have to convert the URL to a path.