【发布时间】:2012-05-09 04:18:14
【问题描述】:
我正在尝试将 NSNumber 传递给正在工作的 UInt32。然后我试图将 UInt32 填充到 NSData 对象中。但是这就是事情变得有点古怪的地方...
当我尝试将 NSData 对象中的内容写入字符串时,它会返回 (null)。
这就是我的代码的样子,我认为这与我将 CACHE_VALUE 传递给 requestCacheData 的方式有关。但我不完全确定为什么。
// Use the correctly returned cache number
UInt32 CACHE_VALUE = [cacheNumber intValue];
NSLog(@"%lu", CACHE_VALUE); //gives me the correct integervalue
NSData * requestCacheData = [[NSData alloc] initWithBytes:&CACHE_VALUE length:sizeof(CACHE_VALUE)];
NSString *myString = [[NSString alloc] initWithData:requestCacheData encoding:NSUTF8StringEncoding];
NSLog(@"%@", myString); //outputs (null)
任何帮助将不胜感激。
【问题讨论】:
标签: iphone ios nsdata nsnumber uint32