Skip to content

Instantly share code, notes, and snippets.

@FredericJacobs
Last active August 29, 2015 13:56
Show Gist options
  • Save FredericJacobs/9190073 to your computer and use it in GitHub Desktop.
Save FredericJacobs/9190073 to your computer and use it in GitHub Desktop.
-(std::string *) objcDataToCppString:(NSData*)objcData {
return new std::string([objcData bytes], [objcData length]);
}
-(NSData*) cppStringToObjcData:(const std::string)cppString {
return [NSData dataWithBytes:cppString.c_str() length:cppString.size()];
}
@FredericJacobs
Copy link
Author

Warning: This is an updated Gist. @lrz helped me fix the bugs :)

@lrz
Copy link

lrz commented Feb 24, 2014

I also recommend to return a pointer (or fill the string by reference) to avoid copying cost.

-(std::string *) objcDataToCppString:(NSData*)objcData {
  return new std::string([objcData bytes], [objcData length]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment