@interface CSize<__covariant T> : NSObject
@property T width;
@property T height;
-(id) initWithWidth: (T) width andHeight: (T) height;
-(NSString *) asText;
@end
@implementation CSize
-(id) initWithWidth: (id) width andHeight: (id) height {
self = [super init];
if (self) {
self.width = width;
self.height = height;
}
return self;
}
-(NSString *) asText {
return [NSString stringWithFormat:@"[%@; %@]", self.width, self.height];
}
@end
CSize<NSNumber *> *sizeInt = [[CSize alloc] initWithWidth:@5 andHeight:@8];
NSString *textInt = [sizeInt asText];
//textInt is "[5; 8]"
CSize<NSNumber *> *sizeFloat = [[
CSize alloc] initWithWidth:@3.7 andHeight:@1.58];
NSString *textFloat = [sizeFloat asText];
//textFloat is "[3.7; 1.58]" @end