(iphone) is it okay to define @property for c ++ class / struct?

I mix C ++ and objectc.
In particular, I am adding the class / struct C ++ variable to the object-c header, and if that is legal?

For instance,

@interface MyView : UIView { MyCppClass cppVariable; } @property (nonatomic, assign) MyCppClass cppVariable; @end 

and in the implementation file, @synthesize cppVariable; also.

+4
source share
1 answer

As described in this white paper on Objective-C ++ , you may not have a C ++ Object pointer inside Objective-C classes. They are properly built and destroyed if you use the -fobjc-call-cxx-cdtors in GCC / clang.

The situation for @sythesiz not a C ++ pointer @property not so clear, because there is no documentation. The behavior sometimes depends on the compiler used, as discussed, for example. into this question SO . The Clang team is trying to implement the right things, but I donโ€™t think it is available yet.

So stick with a pointer to C ++ classes if you want @synthesize . Otherwise, implement your own setter and getter.

+4
source

Source: https://habr.com/ru/post/1340942/


All Articles