Reputation: 5487
Is it possible and how to create objects of such classes like NSString from C++ code?
Upvotes: 0
Views: 380
Reputation: 5473
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.
Upvotes: 2