ObjC/Cocoa class for converting size to human-readable string?

前端 未结 8 1873
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 05:41

Is there a simple way to do something like..

[NSMagicDataConverter humanStringWithBytes:20000000]

..which would return \"19.1MB\"?

8条回答
  •  爱一瞬间的悲伤
    2020-11-28 06:00

    Starting in OS X 10.8 and iOS 6, you can use NSByteCountFormatter.

    Your example would look like this:

    [NSByteCountFormatter stringFromByteCount:20000000 countStyle:NSByteCountFormatterCountStyleFile];
    

提交回复
热议问题