Skip to content

Instantly share code, notes, and snippets.

@agammahajan1
Last active April 18, 2022 11:15
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 agammahajan1/e7b9c38e2c8781369fe408e136dffd2a to your computer and use it in GitHub Desktop.
Save agammahajan1/e7b9c38e2c8781369fe408e136dffd2a to your computer and use it in GitHub Desktop.
func isStorageAvailable() -> Bool {
let fileURL = URL(fileURLWithPath: NSHomeDirectory() as String)
do {
let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey, .volumeTotalCapacityKey])
guard let totalSpace = values.volumeTotalCapacity,
let freeSpace = values.volumeAvailableCapacityForImportantUsage else {
return false
}
if freeSpace > minimumSpaceRequired {
return true
} else {
// Capacity is unavailable
return false
}
catch {}
return false
}
@trantorGurjitSingh
Copy link

What's the value of minimumSpaceRequired according to you?

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