There are several errors/issues in your code:
[bufferToSend initWithCapacity:0];
for the already initialized object makes no sense.- The
[[NSString alloc] initWithString:...]
call is completely unnecessary, as[textfield1 text]
is already a string. appendData:
expectsNSData
, notNSString
. This is probably causing the crash. (Did the compiler not display a warning about incompatible types?)
The code then reduces to:
NSMutableData* bufferToSend;
bufferToSend = [[NSMutableData alloc] initWithCapacity:0];
NSData *dataFromTextField = [[textfield1 text] dataUsingEncoding:NSUTF8StringEncoding];
[bufferToSend appendData:dataFromTextField];