iPhone 3.1.3用のアプリを開発しています。私はすべての初期化時にセットアップに自分のフィールド(形状、場所、範囲)を必要とするので、プログラマが-(id)init;
を使わせたくない- (id)initを使わないでください。メソッド
@interface Pattern : NSObject {
NSMutableArray* shapes;
NSMutableArray* locations;
CGSize bounds;
}
@property (nonatomic, retain, readonly) NSMutableArray* shapes;
@property (nonatomic, retain, readonly) NSMutableArray* locations;
- (id) initWithNumShapes:(int)numShapes screenSize:(CGSize)screenSize;
- (void) addObject:(Object2D*) newObject;
@end
:
は、私は以下のクラスを持っています。私は、プログラマがこれを使わせたくない:
Pattern* myPattern = [[Pattern alloc] init];
私が実装する方法を知っている:
- (id) initWithNumShapes:(int)numShapes screenSize:(CGSize) screenSize{
if (self = [super init]) {
shapes = [NSMutableArray arrayWithCapacity:numShapes];
locations = [NSMutableArray arrayWithCapacity:numShapes];
bounds = screenSize;
}
return (self);
}
私はそれをどのように行うことができますか?
すばらしい答えです!どうもありがとう! – VansFannel