Contents

MXDiskSpaceUsageMetric

An object representing metrics about your app’s disk space usage.

Declaration

class MXDiskSpaceUsageMetric

Overview

This object provides insights on how your app utilizes disk space and related storage technologies, such as cache folders and clone files.

Disk space is a limited resource shared by many apps. Optimize your app’s disk space usage to provide a better customer experience. People can inspect your app’s disk footprint in Settings, and excessive usage may force them to remove your app to install new apps or perform system updates.

Disk Space Measurements

Modern file systems such APFS provide enhanced features to maximize space utilization, such as file cloning. The disk space usage metric reports size accurately without double counting the cloned files.

For example, if you copy a file using copyItem(at:to:), the file system shows two separate files. However, due to the file system optimization, the copied file shares the same storage space with the original file. If you manually calculate the size of all your files, your calculation may also include the copied file, resulting in a larger size than expected.

Storing App-Specific Files

Use the totalCacheFolderSize property of MXDiskSpaceUsageMetric to gain insights into how the operating system manages your app’s cached content in the field. Placing files in the appropriate directories, such as the cachesDirectory and temporaryDirectory (see File System Basics), allows the system to intelligently manage and purge content when necessary, ensuring optimal disk space utilization and a better user experience.

Topics

Reading file counts

Reading file sizes

Reading disk capacity and space

See Also

Disk usage metrics