Last active
April 18, 2022 11:15
-
-
Save agammahajan1/e7b9c38e2c8781369fe408e136dffd2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the value of
minimumSpaceRequired
according to you?