Search code examples
objective-ccocoacocoa-touchnsformatter

In Cocoa, NSDateFormatter provides a dateFromString: method for parsing strings into date objects. Is there anything similar for NSByteCountFormatter?


In a Objective-C application that I am developing, I need to parse byte count strings to obtain the number of bytes represented by the string. For example, if I have "10 MB" as a String, I would like to parse it to have the number of bytes, which, in this case is 10485760 bytes. NSDateFormatter and NSNumberFormatter can convert in both directions, while I don't find a byteCountFromString: method in NSByteCountFormatter. I have searched if some NSFormatter methods can solve the problem, but I have not found the solution so far. Any help is greatly appreciated. Thanks.


Solution

  • Is there anything similar for NSByteCountFormatter?

    No. NSByteCountFormatter converts a byte count value into a localized description that is formatted with the appropriate byte modifier (KB, MB, GB and so on). Not the other way around.