2

NSFileManager has been renamed to FileManager in Swift 2.3 onwards. So do the defaultManager class method which now just default However when I use.

FileManager.default()

Compiler mis-icntepret and throw error.

default label can only appear in switch statement

Swift 2.3 and Xcode 8 beta 3

Swift Hipster
  • 1,604
  • 3
  • 16
  • 24
  • Tried using a selector and one of the performSelector methods? Or maybe a closure? – Tibrogargan Aug 02 '16 at 05:27
  • 2
    Should be `'default'()` I guess even though autocomplete put the `default()`. Its beta. – MadNik Aug 02 '16 at 05:28
  • As mentioned in the below answer. you should use." ` " not " ' " in order to escape keyword. Anyone know how to write this in a comment avoiding the formatting? – MadNik Aug 02 '16 at 09:36
  • 1
    @MadNik you use the `` tag to surround a backslash and the backtick. – Sweeper Aug 02 '16 at 11:03
  • Some of the swift 3 APIs replace the class method for the shared instance with a property. I don't have the API in front of me by try to verify the current status of the method. – DerrickHo328 Aug 13 '16 at 06:33

2 Answers2

2

I don't know about Swift 2.3, but I think the syntax for escaping a keyword hasn't changed. After all, it's not a major update.

You can use the ` character to escape a keyword so as to use the keyword as an identifier for a variable, method or something else. So you can do this do create a variable named var:

var `var` = 0

So if you just write:

FileManager.`default`()

it should work.

btw I just looked up NSFileManager in the docs. And I found that there is no default() method. Is the docs outdated or something?

enter image description here

Sweeper
  • 213,210
  • 22
  • 193
  • 313
0

This problem is fixed in Swift 3, and the backticks are no longer necessary. Note that the default manager is now a class property rather than a class method. So the correct syntax is:

 FileManager.default
matt
  • 515,959
  • 87
  • 875
  • 1,141