iphone - Use NSMutableData but appendData failed -


when init nsmutabledata 100 length,it append data failed.

self.receivedata = [[nsmutabledata alloc] initwithlength:100]; if (nil == self.receivedata) {     mylog;     return no; } - (void)connection:(nsurlconnection *)aconn didreceivedata:(nsdata *)data {     [self.receivedata appenddata:data];     nsstring *string = [[nsstring alloc] initwithdata:self.receivedata encoding:nsutf8stringencoding];     nslog(@"%@",string);//there can't log string     mylog;     [string release]; } 

but when init 0 length,it can append well

self.receivedata = [[nsmutabledata alloc] initwithlength:0]; if (nil == self.receivedata) {     mylog;     return no; } 

i'm new objective-c, can me ?

there's difference between initwithlength: , initwithcapacity:. initwithlength: gives many bytes of 0s @ beginning of data, while initwithcapacity: hint storage purposes. if try make string out of data 0s @ beginning, empty string.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -