iOS swift 獲取總磁盤空間和可用磁盤空間
KB: 1024 ??
MB: 1024*1024 / KB*1024?
GB: ?MB*1024?
mb = ?size / MB
gb = ?size / GB
kb = ?size / KB
代碼:?
?let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last!
? ? ? ? guard
? letsystemAttributes =try?FileManager.default.attributesOfFileSystem(forPath: documentDirectory),
? ? ? ? ? ? let freeSize = systemAttributes[FileAttributeKey.systemFreeSize]as?NSNumber //?獲取可用的磁盤空間
? ? ? ? ? ? let totalSize = ?systemAttributes[FileAttributeKey.systemSize]as?NSNumber?//獲取總的磁盤空間
? ? ? ? else{
?? ? ? ? ? ?return-1
? ? ? ? }