Search code examples
swiftnsfilemanager

'fileExists' produces 'Bool', not the expected contextual result type 'Bool'


This line of code:

if !FileManager.fileExists(atPath: documentDirectory.appendingPathComponent("newname.pdf"))

is getting an error saying

'fileExists' produces 'Bool', not the expected contextual result type 'Bool'

on Xcode 9.2. What am I missing?


Solution

  • You need to call fileExists on an instance of a FileManager. It's not a class method.

    FileManager provides the default instance that is used in most cases.

    if !FileManager.default.fileExists(atPath: documentDirectory.appendingPathComponent("newname.pdf"))