views:

154

answers:

1
+1  Q: 

Convert a NSString

My situation is explained in the code below. I need to send via a socket NSString drawn from a TextBox

Thank you very much

NSString *string = fieldTesto.txt;
// I Find an istruction for insert s string in to the CFSocketSend
UInt8 message[] = "Hello world";
CFDataRef data = 
             CFDataCreate(NULL, message, sizeof(message));
CFSocketSendData(s, NULL, data, 0);
CFRelease(data);
+3  A: 

You can convert your string to NSData and then use the toll-free bridging to CFData.

NSData *data = [string dataUsingEncoding: NSASCIIStringEncoding];
...
CFSocketSendData(s, NULL, (CFDataRef)data, 0);
pgb
warning: passing argument 3 of 'CFSocketSendData' from incompatible pointer type
zp26
Just fixed it. You only need to cast it properly.
pgb