문제

I am retrieving a fairly large amount of text from a webpage and I would like to build multiple NSMutableData instances with it, of a certain size each. What I am not sure about is how to move on to the second NSMutableData object once the first one fills up. What I want to do is similar to this:

NSInteger dataSize = 1000;
data1 = [[NSMutableData alloc] initWithCapacity:dataSize];
data2 = [[NSMutableData alloc] initWithCapacity:dataSize];
data2 = [[NSMutableData alloc] initWithCapacity:dataSize];

if (//data3 is full) {
    [data2 appendData:data];
} else if (// Data2 is full) {
    [data1 appendData:data];
} else {
    [data3 appendData:data];
}

Or some thing else along those lines. Any suggestions on how I might do this? How does one determine if the NSMutableData object is at capacity?

도움이 되었습니까?

해결책

The NSMutableData will automatically allocate more space when it becomes 'full', so you shouldn't need to worry about it filling up. It works more like a list than an array.

Unless I'm missing something about what you're trying to accomplish, you shouldn't need to do this.

다른 팁

The initWithCapacity method allocates the requested memory right away and additional memory is allocated if it is needed. Here datasize is initial required memory and if the allocated memory is not sufficient then it will automatically allocate the bigger space.

Please take a look on NSMutableDataDocumentation. ;)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top