开发者

Problem with "CFDataRef".

开发者 https://www.devze.com 2022-12-29 19:06 出处:网络
I have a problem with \"CFDataRef. I get the \"data\" field from a \"kCFSocketDataCallBack. \"data\" should correspond to a string received on the socket.

I have a problem with "CFDataRef. I get the "data" field from a "kCFSocketDataCallBack. "data" should correspond to a string received on the socket. How do I convert, for example, in a开发者_JAVA技巧 NSString so I can put my text in a textbox??

Thank you very much

 static void
 AcceptDataCallback(CFSocketRef s,
 CFSocketCallBackType type, CFDataRef
 address, const void *data, void *info)
 {

 //my code for the textBox

 }


You could first try converting to NSData by casting it:

NSData * someData = (NSData*)address;

Then convert the NSData to NSString:

NSString * someString = [[NSString alloc] initWithData:someData encoding:NSASCIIStringEncoding];

Or do it all at once:

NSString * someString = [[NSString alloc] initWithData:(NSData*)address encoding:NSASCIIStringEncoding];

You may have to mess around with the encoding.

0

精彩评论

暂无评论...
验证码 换一张
取 消