Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #import <Foundation/Foundation.h>
  2.  
  3. @interface TestCls: NSObject
  4.  
  5. @property(nonatomic, copy) NSString *name;
  6.  
  7. @end
  8.  
  9. @implementation TestCls
  10.  
  11. - (instancetype)init {
  12. if (self = [super init]) {
  13. [self testFunction];
  14. }
  15. return self;
  16. }
  17.  
  18. - (void)testFunction {
  19. NSLog(@"testFunction %@", self.name);
  20. }
  21.  
  22. @end
  23.  
  24. @interface TestCls (TestCategory)
  25.  
  26. - (void)testFunction;
  27.  
  28. @end
  29.  
  30. @implementation TestCls (TestCategory)
  31.  
  32. - (void)testFunction {
  33. NSLog(@"another testFunction");
  34. }
  35.  
  36. - (Class)class {
  37. return [NSString class];
  38. }
  39.  
  40. @end
  41.  
  42. int main() {
  43. TestCls *testCls = [[TestCls alloc] init];
  44. [testCls testFunction];
  45. NSLog(@"which class is testCls %@", [testCls class]);
  46. NSString *testStr = @"testStr";
  47. NSLog(@"which class is testStr %@", [testStr class]);
  48. }
  49.  
  50. @implementation NSString (Test_Category)
  51.  
  52. - (Class)class {
  53. return [NSNumber class];
  54. }
  55.  
  56. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement