I’m looking to use the Zimt library and the ZTWebSocket class has a ‘send’ method that accepts NSString with this signature:
- (void)send:(NSString *)message;
I want to send along data as a UTF8 string but the method only accepts regular NSString. What should I do to avoid the compiler warning? Can I cast from UTF8 to regular string without any problems?
websocket = [[ZTWebSocket alloc] ...];
// 1) this will also generate a warning about incompatible pointer type for the arguments
[websocket send:[message UTF8String]];
// 2) what happens during transmission if I cast this back to a regular string?
[websocket send:(NSString *)[message UTF8String]];
You can’t use
-UTF8Stringsince that returns a standard Cconst char *, not aNSString.The framework you’re using would need to expose a method for changing the encoding, since it must get the bytes from the string at some point using some encoding (unless it uses a deprecated method that doesn’t specify the encoding).
In short, speak to the guys who make the framework and ask their advice 😉
EDIT | I just looked at the source on github.com, and it’s actually hard-coded to use UTF8, so you’re ok.
Excerpt: