When I call -description
on an NSData
object, I see a pretty Hex string of the NSData
object's bytes like:
<f6e7cd28 0fc5b5d4 88f8394b af216506 bc1bba86 4d5b483d>
I'd like to get this representation of the data (minus the lt/gt quotes) into an in-memory NSString
so I can work with it.. I'd prefer not to call -[NSData description]
and then just trim the lt/gt quotes (because I assume that is not a guaranteed aspect of NSData
's public interface and is subject change in the future).
What's the simplest way to get this representation of an NSData
object into an NSString
object (other than calling -description
)?
description
's output may change across system versions. For example,-[NSDate description]
was, pre-Lion, documented as returning a string with exactly the same format as was required for-[NSDate initWithString:]
; that guarantee is no longer made. Brief discussion here: #5838277 – Sacrificedescription
should be used for debugging purposes only, because you have no guaranty that the value returned by thedescription
method won't change in future releases (even if it is unlikely). For example nothing tells your that Apple won't decide some day that if[NSData length]>200
, then the string returned bydescription
will be clipped in the middle... or anything similar. So this is why its may not be a good practice to rely on what is returned bydescription
for anything else than debugging/logging. – Kwangchowan