You can get the free space and capacity of a particular volume using code like this.
func printVolumeCapacities(url: URL) {
let values: URLResourceValues = try! url.resourceValues(forKeys: [.volumeAvailableCapacityKey, .volumeTotalCapacityKey])
print(values.volumeAvailableCapacity!)
print(values.volumeTotalCapacity!)
}
Note This is Swift 3 code, compiling with Xcode 8.0b4. These APIs are much less fun to call from Swift 2 )-:
So, if you get your Documents directory URL and pass it into this, it’ll tell you how much space you have to work with.
I wrote:
What do you want to do with this value? Display it to the user? If not that then what?
You wrote:
yes, i would just like to get the total and available disk space in xcode …
That doesn’t really answer my question. While the above code works, whether it does what you want to do depends on your requirements, and you’ve not really explained those. Until you do, I can’t give you a decent answer.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"