I see from another post I was conflating "ivars" with "properties". With regards to the setters, I have some C++ libraries, and I was thinking about having "property" wrappers in an Objective C object doing setting and getting into values in the C++ object.

So here is a slightly more detailed scenario while still trying to keep it as simple as possible.

My "Model" is captured in C++ code (i.e., "CppObj" below). I want to use normal Cocoa "View" objects (e.g., an NSTextField) and "Controller" objects (e.g., NSObjectController). So I create an Objective C object ("MyWrapper ") to wrap the C++ object, and access to the C++ content is done through "properties". Both the setters and getters reach down into the C++ object to set or get its values.

Things seem to be working. I just wanted to make sure I wasn't doing something illegal or not supported. I guess I have always had properties associated with actual variables, so it never occurred to me before that they are really independent things.

Todd


//----------------- C++ model ----
class CppObj {
public:
        int     myInt;
};


//----------------- Objective-C++ wrapper ----
@interface MyWrapper : NSObject  {
        CppObj* p_cppObj;
}
-(int)myInt;
-(void)setMyInt:(int)newVal;
@end



//----------------- getter/setter wrappers of C++ model ----
-(int)myInt
{
        return p_cppObj->myInt;
}

- (void)setMyInt:(int)newVal
{
        p_cppObj->myInt = newVal;
}


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to