C++ to Objective-C conversions
This page shows what is automatically translated and to what.
On the left is the C++
and to the right what the corresponding interface in Objective-C
will be.
Not converted means there will be no automatic translation to a corresponding language object.
Note that any restriction this poses only applies to the public interface of your code (e.g. your public headers). Your internal code can use anything from C++.
Conversion tables
C++ | Objective-C translation |
---|---|
Namespace | Prefix* |
Nested namespace | Prefix* |
Class | Class |
Public function | Class function |
Private function | Not converted |
Virtual function | ??? |
Operator | ??? |
Static member function | Static class function |
Static member variable | Static class variable |
Public const member variable | Readonly property |
Public non const member variable | Readwrite property |
Private member variable | Not converted |
Global variable | Static class property** |
Global static variable | Static class property** |
Free function | Static class function** |
Overloaded function | Class function*** |
Enum | NS_ENUM |
Scoped enum | NS_ENUM |
Templated class/function | Not converted**** |
Specialized class template | Class*** |
Specialized function template | Function*** |
Documentation | Documentation |
* Prefix on all classes and free functions in the namespace.
** Wrapped in a class with a name that starts with the module name.
*** The naming convention for these classes and functions can be found under the Naming Convention page.
**** No direct translation to Objective-C. Will not emit warning.
C++ operator | Objective-C operator |
---|---|
operator+ | ??? |
operator- | ??? |
operator* | ??? |
operator/ | ??? |
operator% | ??? |
operator+= | ??? |
operator-= | ??? |
operator*= | ??? |
operator/= | ??? |
operator%= | ??? |
operator== | ??? |
operator!= | ??? |
operator> | ??? |
operator>= | ??? |
operator< | ??? |
operator<= | ??? |
operator[] | ??? |
operator() | ??? |
operator= | Not converted |
operator<< | Not converted |
operator>> | Not converted |
operator++ | Not converted |
operator-- | Not converted |
C++ Standard library class | Objective-C translation |
---|---|
std::array | NSArray |
std::complex | ??? |
std::deque | NSArray |
std::filesystem::path | NSString |
std::forward_list | Not converted |
std::function | ??? |
std::list | NSArray |
std::map | NSDictionary |
std::multimap | Not converted |
std::multiset | Not converted |
std::optional | Value or nil |
std::pair | NSArray |
std::priority_queue | Not converted |
std::queue | Not converted |
std::set | NSOrderedSet |
std::shared_ptr | Value* |
std::stack | Not converted |
std::string | NSString |
std::string_view | NSString |
std::tuple | NSArray |
std::unique_ptr | Value |
std::unordered_map | NSDictionary |
std::unordered_multimap | Not converted |
std::unordered_multiset | Not converted |
std::unordered_set | NSSet |
std::valarray | NSArray |
std::variant | ??? |
std::vector | NSArray |
* After using a shared_ptr
, the object is now always managed by a shared_ptr
.
C++ builtin type | Objective-C translation |
---|---|
bool | bool |
char | char |
char16_t | char16_t |
char32_t | char32_t |
double | double |
float | float |
int | int |
int8_t | int8_t |
int16_t | int16_t |
int32_t | int32_t |
int64_t | int64_t |
long double | long double |
long int | long int |
long long int | long long int |
short int | short int |
signed char | signed char |
uint8_t | uint8_t |
uint16_t | uint16_t |
uint32_t | uint32_t |
uint64_t | uint64_t |
unsigned char | unsigned char |
unsigned int | unsigned int |
unsigned long int | unsigned long int |
unsigned long long int | unsigned long long int |
unsigned short int | unsigned short int |
wchar_t | wchar_t |
void | void |