Skip to content

Instantly share code, notes, and snippets.

@riteshhgupta
Created October 3, 2017 04:14
Show Gist options
  • Save riteshhgupta/0bce24a1ce8a9b93f857fc8cf0e41ba3 to your computer and use it in GitHub Desktop.
Save riteshhgupta/0bce24a1ce8a9b93f857fc8cf0e41ba3 to your computer and use it in GitHub Desktop.
extension FileManager {
static var documentsDirectory: URL {
return FileManager
.default
.urls(for: .documentDirectory, in: .userDomainMask)
.last!
}
}
extension String {
var fileName: String {
return "your_app_unique_prefix_"
+ self
+ ".json"
}
var fileURL: URL {
return FileManager
.documentsDirectory
.appendingPathComponent(fileName)
}
}
extension URL {
var fileContent: Data? {
return FileManager
.default
.contents(atPath: path)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment