Created
September 1, 2015 21:32
-
-
Save Kozlov-V/fc12e2111930012e4553 to your computer and use it in GitHub Desktop.
StringValueBytes
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
- (NSString *)readableValueWithBytes:(id)bytes{ | |
NSString *readable; | |
//round bytes to one kilobyte, if less than 1024 bytes | |
if (([bytes longLongValue] < 1024)){ | |
readable = [NSString stringWithFormat:@"1 KB"]; | |
} | |
//kilobytes | |
if (([bytes longLongValue]/1024)>=1){ | |
readable = [NSString stringWithFormat:@"%lld KB", ([bytes longLongValue]/1024)]; | |
} | |
//megabytes | |
if (([bytes longLongValue]/1024/1024)>=1){ | |
readable = [NSString stringWithFormat:@"%lld MB", ([bytes longLongValue]/1024/1024)]; | |
} | |
//gigabytes | |
if (([bytes longLongValue]/1024/1024/1024)>=1){ | |
readable = [NSString stringWithFormat:@"%lld GB", ([bytes longLongValue]/1024/1024/1024)]; | |
} | |
//terabytes | |
if (([bytes longLongValue]/1024/1024/1024/1024)>=1){ | |
readable = [NSString stringWithFormat:@"%lld TB", ([bytes longLongValue]/1024/1024/1024/1024)]; | |
} | |
//petabytes | |
if (([bytes longLongValue]/1024/1024/1024/1024/1024)>=1){ | |
readable = [NSString stringWithFormat:@"%lld PB", ([bytes longLongValue]/1024/1024/1024/1024/1024)]; | |
} | |
return readable; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment