Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Introduction to Core Data with Swift 2 Understanding the Core Data Stack The Documents Directory

Jack Farr
Jack Farr
7,961 Points

Cannot call value of non-function type 'FileManager'

I typed out the script and was told to change NSFileManager to FileManager. But once I changed it it told me it cannot call value of non-function type 'FileManager'

let urls = FileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)

Because you mentioned you had to change NSFileManager to FileManager I'm guessing you're using Swift 3. Apple made some serious changes to the language and the code of this course is not Swift 3 (or not yet, they will update). For your code, this should work:

lazy var applicationDocumentsDirectory: URL = { let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) return urls[(urls.endIndex - 1)] }()

Chances are high that you have to update every piece of code of this course to Swift 3 manually. You can do this in the meantime while taking the course, it won't be fun.

You can also download the project-files, open them with Xcode 8 (which I'm guessing you're working with) and let Xcode converting them for you to Swift 3.

2 Answers

eberhapa
eberhapa
51,495 Points

Change it to let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)

Graham Connolly
Graham Connolly
25,475 Points

If you are using the latest Xcode (Xcode 8), you can enable Swift 2.3 by going to build settings -> Swift Compiler Version -> Use Legacy Swift Language Version and set this to Yes instead of the default No.