Is it possible and how to create objects of such classes like NSString from C++ code?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ve got 3 options:
1) If you’re mainly writing in C++ and want to communicate with an API that expects cocoa strings and collections, then Core Foundation is a C (and therefore C++) api for creating and interacting with many of Foundation’s classes. Many NS-prefixed cocoa classes have a CF-prefixed equivalent, and can be used interchangeably.
2) If you’re integrating c++ code with objective-c code, then you have the option of compiling the interface classes as objective-c++ which allows you to mix both in the same source file. So it’s valid to do stuff like
vector.push_back( [NSString stringWithFormat:@"string"] )3) It is possible to access (near enough) the whole objective-c language as a C runtime library by including
<objc/runtime.h>. I can’t actually think of a good reason for using this over one of the other 2, but it might be worth keeping in mind if there’s a good reason you can’t.