@protocol Link
@property id next
@end
@interface MyClass : NSObject {
NSTimeInterval intervalSinceReferenceDate;
CGFloat gratuuitousFloat;
id nextLink;
}
@property (readonly) NSTimeInterval creationTimestamp;
@property (copy) NSString *name;
@property (readonly, getter=nameAndAgeAsString) NSString *nameAndAge;
@implementation MyClass
@synthesize creationTimestamp = intervalSinceReferenceDate, name;
// Synthesizing 'name' is an error in legacy runtimes;
// in modern runtimes, the instance variable is synthesized.
@synthesize next = nextLink;
// Uses instance variable "nextLink" for storage.
@dynamic gratuitousFloat;
// This directive is not strictly necessary.
- (CGFloat)gratuitousFloat {
return gratuitousFloat;
}
- (void)setGratuitousFloat:(CGFloat)aValue {
gratuitousFloat = aValue;
}
- (NSString *)nameAndAgeAsString {
return [NSString stringWithFormat:@"%@ (%fs)", [self name],
[NSDate timeIntervalSinceReferenceDate] - intervalSinceReferenceDate];
}
- (id)init {
if (self = [super init]) {
intervalSinceReferenceDate = [NSDate timeIntervalSinceReferenceDate];
}
return self;
}
- (void)dealloc {
[nextLink release];
[name release];
[super dealloc];
}
@end
0 评论: (+add yours?)
Post a Comment