[英]Generating getters & setters in XCode
我目前正在使用xcode进行某些c ++开发,并且需要生成getter和setter。
我知道的唯一方法是以Objective C风格生成吸气剂和吸气剂
像这样-(string)name; -(void)setName:(string)value;
我不要这个 我想在头文件中使用带有实现和声明的c ++样式生成。
任何想法...?
听起来您只是在寻找一种减少一直写getter / setter(即property / synthesize语句)麻烦的方法?
在突出显示一个我认为非常有用的成员变量后,您可以在XCode中使用一个免费的宏来自动生成@property和@synthesize语句:)
如果您正在寻找更强大的工具,则可能要签出另一个名为Accessorizer的付费工具。
目标C!= C ++。
ObjectiveC使用@property和@synthesize关键字为您实现自动实现(我目前自己靠着ObjectiveC,只有一台Mac!)。 C ++并非如此,因此您只需要自己编写函数即可。
oo
inline int GetBar( ) { return b; }
inline void SetBar( int b ) { _b = b; }
要么
oo
int GetBar( );
void SetBar( int b );
Foo.cpp
#include "Foo.h"
int Foo::GetBar( ) { return _b; }
void Foo::SetBar( int b ) { _b = b; }
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.