ゲッターの生成& XCodeのセッター
-
08-07-2019 - |
質問
現在、一部のC ++開発にxcodeを使用しています。ゲッター&を生成する必要がありますセッター。
私が知っている唯一の方法は、ゲッターとアンプを生成することですObjective Cスタイルのセッター
このようなもの -(文字列)名; -(void)setName:(string)value;
これは必要ありません。実装を使用したC ++スタイルの生成が必要です&ヘッダーファイルで使用する宣言。
アイデア...?
他のヒント
Objective 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
所属していません StackOverflow