次のような新しいクラスを定義します。
@interface SomeClass : NSObject {
int wide;
}
- (id)initWithWide:(int)value;
@end
次のように initWithWide メソッドを実装すると、次のようになります。
@implementation SomeClass
- (id)initWithWide:(int)value {
self = [super init];
wide = value;
}
@end
Xcode でエラーが表示されます: "Expected identifier or'('"
. 「ワイド」変数名をelseに変更するとOKです。Objective-Cの変数名として「ワイド」を使用できないように見えますか?
ワイドに名前を変更したので、これは問題なく動作します:
@interface SomeClass : NSObject {
int wide1;
}
- (id)initWithWide:(int)value;
@end
@implementation SomeClass
- (id)initWithWide:(int)value {
self = [super init];
wide1 = value;
}
@end