JohnSundell / Files

A nicer way to handle files & folders in Swift
MIT License
2.53k stars 182 forks source link

Folder(path: <path>) doesn't seem to work #97

Closed thejeff77 closed 4 years ago

thejeff77 commented 4 years ago

A lot of the below code from the docs is causing me issue:

let folder = try Folder(path: "/users/john/folder")
let file = try folder.createFile(named: "file.json")
try file.write(string: "{\"hello\": \"world\"}")
try file.delete()
try folder.delete()

That first line gives:

Incorrect argument label in call (have 'path:', expected 'storage:')

As the init(path:) is in the parent protocol extension, I'm not sure quite how this works. This project is making me see there is a lot I don't know about swift.

Any help or input is appreciated.

Amzd commented 4 years ago

The only syntax issue in your code is the write function, it should be:

try file.write("{\"hello\": \"world\"}")

Omitting Argument Labels: https://docs.swift.org/swift-book/LanguageGuide/Functions.html#ID526

JohnSundell commented 4 years ago

Yeah, that particular code sample from the README hadn't been updated for Files' new API, which was introduced in 4.0. Fixed here: https://github.com/JohnSundell/Files/commit/635e51be758a25e6f956ba57edb5a9eff14be076.