Guest User

Untitled

a guest
Jan 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <Foundation/Foundation.h>
  2.  
  3. @class MyNum;
  4. @class MyFloat;
  5. @class MyInt;
  6.  
  7. @interface MyNum : NSObject
  8. - (id)initWithFloat:(float)value;
  9. - (id)initWithInt:(int)value;
  10. - (void)print;
  11. @end
  12.  
  13. @interface MyFloat : MyNum
  14. @property float value;
  15. - (id)initWithFloat:(float)value;
  16. @end
  17.  
  18. @interface MyInt : MyNum
  19. @property int value;
  20. - (id)initWithInt:(int)value;
  21. @end
  22.  
  23. @implementation MyInt
  24. @synthesize value = _value;
  25. - (id)initWithInt:(int)value {
  26.     if ((self = [super init]))
  27.     {
  28.         self.value = value;
  29.     }
  30.     return self;
  31. }
  32. - (void)print {
  33.     NSLog(@"%d",self.value);
  34. }
  35. @end
  36.  
  37. @implementation MyFloat
  38. @synthesize value = _value;
  39. - (id)initWithFloat:(float)value {
  40.     if ((self = [super init]))
  41.     {
  42.         self.value = value;
  43.     }
  44.     return self;
  45. }
  46. - (void)print {
  47.     NSLog(@"%f",self.value);
  48. }
  49. @end
  50.  
  51. @implementation MyNum
  52.  
  53. - (id)initWithFloat:(float)value {
  54.     return [[MyFloat alloc] initWithFloat:value];
  55. }
  56. - (id)initWithInt:(int)value {
  57.     return [[MyInt alloc] initWithInt:value];
  58. }
  59. - (void)print {
  60.     [self doesNotRecognizeSelector:_cmd];
  61. }
  62. @end
  63.  
  64. int main (int argc, const char * argv[])
  65. {
  66.     @autoreleasepool {
  67.         for (int i = 0; i < 10000; i++) {
  68. //          Test 1
  69.             MyNum *floatValue = [[MyNum alloc] initWithFloat:32.0];
  70.             MyNum *intValue = [[MyNum alloc] initWithInt:32];
  71. //          Test 2
  72. //            MyFloat *floatValue = [[MyFloat alloc] initWithFloat:32.0];
  73. //            MyInt *intValue = [[MyInt alloc] initWithInt:32];
  74.             [floatValue print];
  75.             [intValue print];
  76.         }
  77.     }
  78.     return 0;
  79. }
Add Comment
Please, Sign In to add comment