당신은 인스턴스 변수 (예)@synthesize의 메서드는 무엇입니까? 당신이 재산을 합성 할 때
[newPlanet setName:@"Jupiter"];
[newPlanet setMass:57];
NSString *closestName = [newPlanet name];
int largestMass = [newPlanet mass];
CelestialBody *newMoon = [[CelestialBody alloc] initWithName:@"Callisto"];
[self setMoon:newMoon];
[newMoon release];
각각 세터와 게터를 얻을 수 있지만, 당신은 또한 사용하여 객체를 해제 할 수있는 능력을 얻을
@interface CelestialBody : NSObject {
NSString *name;
}
...
@interface Planet : NSObject {
NSString *name;
int mass;
CelestialBody *moon;
}
@property(nonatomic, retain) NSString *name;
@property(assign) int *mass;
@property(nonatomic, retain) CelestialBody *moon;
...
@implementation Planet
@synthesize name;
@synthesize mass;
@synthesize moon;
...
(아래 참조). ..
// Releases the object (frees memory) and sets the object pointer to nil.
[self setMoon: nil];
물론 각 클래스에 대한 dealloc이 있습니다.
// Moon
-(void)dealloc {
[name release];
[super dealloc];
}
// Planet
-(void)dealloc {
[name release];
[moon release];
[super dealloc];
}
나는이 권리를 얻고 있습니까?
게리
천체에 달이 하나 이상 있으면 어떻게됩니까? –
더 많은 공식적이거나 유용한 것을 디자인하지 않은 점을 강조하는 예로 한 달만 있습니다. – fuzzygoat