I have been using a JSON file for storing configuration parameters for a command line tool I am writing. Some of these configuration items are paths to various directories like this:
{ "codeRepo" : "/Users/Blob/myRepo" }
And I have a Decodable Swift struct that can by instantiated by this configuration file:
struct Config: Decodable { let codeRepo: URL }
When your JSONDecoder deserializes the JSON object into the
URL it will not create a File URL. This is important for some other classes in
Foundation, such as Process
.
Process
requires it's
currentDirectoryURL
and executableURL
items to be set to file
URLs (e.g. created with the URL(fileURLWithPath:...)
initializers) otherwise
it will throw the following Objective-C exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteTask setExecutableURL:]: non-file URL argument'
This tool is for macOS, but now I am genuinely curious what
would happen on Linux since there is no Objective-C backing for Process
.