convert NSData Length from bytes to megs

前端 未结 3 2053
抹茶落季
抹茶落季 2021-02-03 19:20

I am trying to NSLog the number of megs my NSData object is however currently all I can get is bytes by using

NSLog(@\"%u\", myData.le         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-03 19:57

    For Swift 3, in Mb:

    let countBytes = ByteCountFormatter()
    countBytes.allowedUnits = [.useMB]
    countBytes.countStyle = .file
    let fileSize = countBytes.string(fromByteCount: Int64(dataToMeasure!.count))
    
    print("File size: \(fileSize)")
    

提交回复
热议问题