In questo turial imparerete come convertire i Bytes in un formato facilmente leggibile da tutti (KBs, MBs,GBs ecc.).
Il codice ritorna una NSString contenente il risultato convertito.

 
- (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;
}
 

fonte: www.sastgroup.com ? Vai al post originale