正しい用語を使用したかどうかはわかりませんが、昨日客観的な実験を始めたばかりで、ac# のバックグラウンドから来たので、c# の用語を使用する可能性があることを理解してください。
とは言うものの。私は2つのクラスを持っています。他のクラスをプロパティとして使用する 1 つのメイン クラス:
@class Fighter;
@interface Match : NSObject{
int Id;
Fighter *Fighter;
int FScore;
}
@property int Id, FScore;
@property Fighter *Fighter;
@end
*実装:
@implementation Match
@synthesize Id, FScore, Fighter;
@end
これは参照されるクラスです:
@interface Fighter : NSObject{
int Id;
NSString *Name;
}
@property int Id;
@property NSString *Name;
@end
@implementation Fighter
@synthesize Id, Name;
@end
これがオブジェクトのインスタンスを作成する方法です
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
Match *match = [[Match alloc]init];
match.Id = 1;
match.Fighter = [[Fighter alloc]init];
match.Fighter.Id = 9;
match.Fighter.Name = @"womp";
}
ここで、ファイター インスタンスに値を割り当てる際にショートカットのようなものがあるかどうか疑問に思っていました。c# のように、次のようなことができます。
match.Fighter = new Fighter{ Id = 9, Name = "womp" };
そのクラスまたは他のクラスにさらにいくつかのプロパティを追加する可能性がある場合に備えて知りたいです。
PS。
[Class new] より [[Class alloc] init] を使用した方が良いですか??
ありがとう!!!