NSString到NSData没有编码

时间:2017-04-19 14:30:26

标签: objective-c

什么是反向代码:

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

到目前为止,我试过了:

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

然而token!= origToken

我无法改变:

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

因为我为这段代码编写单元测试

1 个答案:

答案 0 :(得分:0)

%@ format说明符等同于调用description方法。

其输出为"A string that contains a hexadecimal representation of the object’s contents in a property list format."

如下测试怎么样?

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

ASSERT([token isEqualToString:tokenDesc]);