Skip to content

Instantly share code, notes, and snippets.

@pfandrade
Created October 22, 2017 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfandrade/87c923d1a803f1588227e47c2fd72fd9 to your computer and use it in GitHub Desktop.
Save pfandrade/87c923d1a803f1588227e47c2fd72fd9 to your computer and use it in GitHub Desktop.
Retrieving the iOS simulator Library/Caches folder URL
if let simulatorSharedDir = ProcessInfo().environment["SIMULATOR_SHARED_RESOURCES_DIRECTORY"] {
// running on the simulator. We'll write to ~/Library/Caches
let simulatorHomeDirURL = URL(fileURLWithPath: simulatorSharedDir)
let cachesDirURL = simulatorHomeDirURL.appendingPathComponent("Library/Caches")
XCTAssertTrue(FileManager.default.isWritableFile(atPath: cachesDirURL.path), "Cannot write to simulator Caches directory")
let sharedFolderURL = cachesDirURL.appendingPathComponent("Secrets")
XCTAssertNoThrow( try FileManager.default.createDirectory(at: sharedFolderURL, withIntermediateDirectories: true, attributes: nil), "Failed to create shared folder \(sharedFolderURL.lastPathComponent) in simulator Caches directory at \(cachesDirURL)")
return sharedFolderURL
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment