how i could append nsdata, i would append lenght data on first message to send on socket i use code like this but error on runing.
int lendata = [message length];
NSData *firstdata = [NSData dataWithBytes: &lendata length: sizeof(lendata)];
NSData *mdata = [message dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *seconddata = [NSData dataWithData:mdata];
[firstdata appendData:secondata];
please tell if there is another way Thanks for your help.
Glancing into my crystal ball:
You are declaring
seconddata
as anNSMutableData
instance, but then you initialize it using[NSData dataWithData:]
instead of[NSMutableData dataWithData:
], soseconddata
won't be mutable in the end and you cannot append to it.You are trying to append to
firstdata
, which is not mutable either.Solution: make
firstdata
mutable:Then you can safely drop
mdata
andseconddata
as they are not needed anymore.check above code for append