我现在使用的Xcode一些C ++开发与我需要生成getter和setter方法。
我所知道的唯一的办法就是生成的目标C风格的getter和setter方法
像这样 - (字符串)名称; - (无效)的setName:(字符串)值;
我不希望这一点; 我想实现和声明在头文件中使用C ++风格的产生。
任何想法...?
我现在使用的Xcode一些C ++开发与我需要生成getter和setter方法。
我所知道的唯一的办法就是生成的目标C风格的getter和setter方法
像这样 - (字符串)名称; - (无效)的setName:(字符串)值;
我不希望这一点; 我想实现和声明在头文件中使用C ++风格的产生。
任何想法...?
这听起来像你只是在寻找一种方式,以减少写入getter / setter方法的麻烦(即财产/综合报表)所有的时间吗?
有一个免费的宏可以在XCode中使用,甚至产生@property,并强调一个成员变量,我觉得真正有用的:)后自动@synthesize声明
如果你正在寻找一个更强大的工具,还有另一个名为支付工具Accessorizer ,你可能想看看。
目标!C = C ++。
的ObjectiveC让你使用@property和@synthesize关键字自动执行(我目前倾向的ObjectiveC自己,刚刚得到一台Mac!)。 C ++没有什么喜欢,所以你只需要自己写的功能。
foo.h中
inline int GetBar( ) { return b; }
inline void SetBar( int b ) { _b = b; }
要么
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