1

What is reverse code for:

NSString *token = [NSString stringWithFormat:@"%@",tokenData];

So far I tried:

NSString *tokenStr = @"<e307808e 2e443d7d ef35f248 aafc5e97 fb8e1cba d65d8ac1 88441028 3bd7b383>";
NSData * tokenData = [tokenStr dataUsingEncoding:NSUTF8StringEncoding];
NSString *origToken = [NSString stringWithFormat:@"%@",tokenData];

However token != origToken

I cannot change:

NSString *token = [NSString stringWithFormat:@"%@",tokenData];

because I write Unit test for this code

snaggs
  • 5,543
  • 17
  • 64
  • 127
  • The "reverse" (which is not really a reverse, but): http://stackoverflow.com/questions/7317860/converting-hex-nsstring-to-nsdata – Larme Apr 19 '17 at 14:47
  • @Larme yes, I found solution, tnx: http://stackoverflow.com/a/35334124/1631379 – snaggs Apr 19 '17 at 14:48

1 Answers1

0

%@ format specifier is equivalent to invoking description method.

Its output is "A string that contains a hexadecimal representation of the object’s contents in a property list format."

How about testing as below?

NSString *token = [NSString stringWithFormat:@"%@",tokenData];
NSString *tokenDesc = [tokenData description];

ASSERT([token isEqualToString:tokenDesc]);
9dan
  • 4,222
  • 2
  • 29
  • 44