Search code examples
iosios7objective-c++ios7.1

Can I use property for C++ variable?


I am using Objective-C++. Can I create a property of C++ class type?

I tried but it reports must be inherited from NSObject.


Solution

  • You can, but it cannot be a strong or weak reference (if you need that, look up std::shared_ptr and std::weak_ptr).

    class C {};
    
    @interface D
    
    @property(nonatomic, assign) C p;
    
    @end