Guest User

Untitled

a guest
Oct 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. private func sharedFolderURL() -> URL {
  2.  
  3. if let simulatorSharedDir = ProcessInfo().environment["SIMULATOR_SHARED_RESOURCES_DIRECTORY"] {
  4. // running on the simulator. We'll write to ~/Library/Caches
  5. let simulatorHomeDirURL = URL(fileURLWithPath: simulatorSharedDir)
  6. let cachesDirURL = simulatorHomeDirURL.appendingPathComponent("Library/Caches")
  7. XCTAssertTrue(FileManager.default.isWritableFile(atPath: cachesDirURL.path), "Cannot write to simulator Caches directory")
  8. let sharedFolderURL = cachesDirURL.appendingPathComponent("Secrets")
  9. XCTAssertNoThrow( try FileManager.default.createDirectory(at: sharedFolderURL, withIntermediateDirectories: true, attributes: nil), "Failed to create shared folder \(sharedFolderURL.lastPathComponent) in simulator Caches directory at \(cachesDirURL)")
  10. return sharedFolderURL
  11. }
  12. else {
  13. // running on the device. We'll write to the AppGroup folder
  14. guard let appGroupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: AppGroupName) else {
  15. XCTFail("Failed to get URL for app group \(AppGroupName). Check your entitlements.")
  16. fatalError()
  17. }
  18. return appGroupURL
  19. }
  20. }
Add Comment
Please, Sign In to add comment