Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tonyarnold/6dc39048743d2eb4ee16 to your computer and use it in GitHub Desktop.
Save tonyarnold/6dc39048743d2eb4ee16 to your computer and use it in GitHub Desktop.
//
// Copyright (c) 2014 Tony Arnold & The CocoaBots. All rights reserved.
import Foundation
extension NSFileManager
{
func applicationSupportDirectoryURL() -> NSURL?
{
let directories = URLsForDirectory(
NSSearchPathDirectory.ApplicationSupportDirectory,
inDomains: NSSearchPathDomainMask.UserDomainMask)
if let directoryURL = directories[directories.endIndex - 1] as? NSURL
{
return directoryURL
}
return nil
}
}
//
// Copyright (c) 2014 Tony Arnold & The CocoaBots. All rights reserved.
import XCTest
import SwiftlyCoreData
class NSFileManagerAdditions: XCTestCase
{
func testApplicationSupportDirectoryURLWorks()
{
let appSupport = NSFileManager.applicationSupportDirectoryURL()
XCTAssertNotNil(appSupport, message: "Should not be nil")
}
}
@tonyarnold
Copy link
Author

I get the following error:

NSFileManagerAdditionsTests.swift:12:26: error: ambiguous use of 'applicationSupportDirectoryURL'
        let appSupport = NSFileManager.applicationSupportDirectoryURL()
                         ^
SwiftlyCoreData.NSFileManager:2:20: note: found this candidate
  @objc class func applicationSupportDirectoryURL() -> NSURL?
                   ^
SwiftlyCoreData.NSFileManager:2:52: note: found this candidate
  @objc(applicationSupportDirectoryURL) class func applicationSupportDirectoryURL() -> NSURL!

@jonsterling
Copy link

Weird, I pasted all this into a "playground" and it worked for me...

@tonyarnold
Copy link
Author

Pasting this into a playground makes the playground stop working for me 😖

@vascoorey
Copy link

@tonyarnold this seemed to work for me (not in the playground tho)

extension NSFileManager
  {

  class func applicationSupportDirectoryURL() -> NSURL? {
    return defaultManager().applicationSupportDirectoryURL()
  }

  func applicationSupportDirectoryURL() -> NSURL?
  {
    let directories = URLsForDirectory(
      NSSearchPathDirectory.ApplicationSupportDirectory,
      inDomains: .UserDomainMask)

    return directories[directories.endIndex - 1] as? NSURL
  }
}

edit: condensing code

@tonyarnold
Copy link
Author

Thanks @vascoorey — I get the errors above regardless of whether I declare/use a class function. I think it's a bug.

@vascoorey
Copy link

Damn that's weird indeed @tonyarnold !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment