Question

I am currently using xcode for some c++ development & I need to generate getters & setters.

The only way I know is generating getters & setters in Objective C style

something like this - (string)name; - (void)setName:(string)value;

I dont want this; I want c++ style generation with implementation & declaration for use in the header files.

Any idea...?

Was it helpful?

Solution

It sounds like you're just looking for a way to reduce the hassle of writing getters/setters (i.e. property/synthesize statements) all the time right?

There's a free macro you can use in XCode to even generate the @property and @synthesize statements automatically after highlighting a member variable that I find really helpful :)

If you're looking for a more robust tool, there's another paid tool called Accessorizer that you might want to check out.

OTHER TIPS

Objective C != C++.

ObjectiveC gives you auto-implementation using the @property and @synthesize keywords (I am currently leaning ObjectiveC myself, just got a Mac!). C++ has nothing like that, so you simply need to write the functions yourself.

Foo.h

inline int GetBar( ) { return b; }
inline void SetBar( int b ) { _b = b; }    

or

Foo.h

int GetBar( );
void SetBar( int b );

Foo.cpp

#include "Foo.h"

int Foo::GetBar( ) { return _b; }
void Foo::SetBar( int b ) { _b = b; }

something.h:

@interface something : NSObject
{
   NSString *_sName;  //local
}

@property (nonatomic, retain) NSString *sName;

@end

something.m :

#import "something.h"
@implementation something

@synthesize sName=_sName; //this does the set/get

-(id)init
{
...
self.sName = [[NSString alloc] init];
...
}

...


-(void)dealloc
{
   [self.sName release]; 
}
@end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top