OC文件大小的计算方法,一般多用于清理缓存、下载、统计
可以使用以下方法:
#pragma mark Bt转换
+ (NSString *)axcFileSizeWithToString:(unsigned long long)fileSize
{
NSInteger KB = 1024;
NSInteger MB = KB*KB;
NSInteger GB = MB*KB;
if (fileSize < 10){
return @"0 B";
}else if (fileSize < KB){
return @"< 1 KB";
}else if (fileSize < MB){
return [NSString stringWithFormat:@"%.1f KB",((CGFloat)fileSize)/KB];
}else if (fileSize < GB){
return [NSString stringWithFormat:@"%.1f MB",((CGFloat)fileSize)/MB];
}else{
return [NSString stringWithFormat:@"%.1f GB",((CGFloat)fileSize)/GB];
}
}
以及 其他关于计算文件或内存的方法:
如下:
#pragma mark 获取当前任务所占用的内存(单位:MB)
+ (double)axcUsedMemory
{
task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
kern_return_t kernReturn = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&taskInfo,
&infoCount);
if (kernReturn != KERN_SUCCESS
) {
return NSNotFound;
}
return taskInfo.resident_size / 1024.0 / 1024.0;
}
#pragma mark 获取当前设备可用内存(单位:MB)
+ (double)axcDeviceAvailableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(),
HOST_VM_INFO,
(host_info_t)&vmStats,
&infoCount);
if (kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.free_count) / 1024.0) / 1024.0;
}
只要c、v、command键不坏,没有什么解决不了的问题,如果有,那就买个键盘。
【axc—赵】原创