【发布时间】:2016-12-23 00:36:10
【问题描述】:
我在使用 NSString 时遇到了一些非常奇怪的问题。当我从输入流中读取数据并将数据转换为字符串时,我无法设置与该字符串相等的任何内容。代码如下:
NSString *name = r.URL.lastPathComponent;
NSString *data;
NSInputStream *stream = r.HTTPBodyStream;
uint8_t byteBuffer[1];
[stream open];
if (stream)
{
// Get the request body from the stream. Used for setting the file name
if (stream.hasBytesAvailable)
{
NSInteger bytesRead = [stream read:byteBuffer maxLength:4096];
NSString *temp = [[NSString alloc] initWithBytes:byteBuffer length:bytesRead encoding:NSUTF8StringEncoding];
data = temp; // EXC_BAD_ACCESS thrown here
}
}
我需要将字符串复制到另一个字符串,但我不能。有谁知道为什么会这样?
【问题讨论】:
标签: ios objective-c nsstring