Skip to content

Fix Classes

Silver edited this page Aug 11, 2020 · 3 revisions

Features

  • Support using _ivar, self.property (get set) syntax in method.
  • Support adding properties and weak property
  • Support adding or replace method(instance/class).
  • Support using ORGMethodName to call original method imp.
  • Support Category Syntax
  • Only Creating a new Class can confirm protocol.

Fix existed Class

//if 'ORTestClassProperty' has already exists in Application
//it will add four properties, and add/replace five methods when executing the code in OCRunner.
@interface ORTestClassProperty:NSObject
@property (nonatomic,copy)NSString *strTypeProperty;
@property (nonatomic,weak)id weakObjectProperty;
@property (nonatomic,strong)id strongObjectProperty;
@property (assign, nonatomic) NSInteger count;
@end
@implementation ORTestClassProperty
- (void)otherMethod{
    self.strTypeProperty = @"Mango";
}
- (NSString *)testObjectPropertyTest{
    [self otherMethod];
    return self.strTypeProperty;
}
- (id)testWeakObjectProperty{
    self.weakObjectProperty = self;
    return self.weakObjectProperty;
}
- (id)testStrongObjectProperty{
    self.strongObjectProperty = self;
    return self.strongObjectProperty;
}
- (id)testIvarx{
    _strTypeProperty = @"Mango-testIvar";
    return _strTypeProperty;
}
- (NSInteger)testOriginalMethod{
    return 1 + [self ORGtestOriginalMethod];
}
@end

Create a new Class

//same to OC: create a new Class 'TestObject', and the instance of 'TestObject' will confirm the Protocol2
@interface TestObject : NSObject <Protocol2>
@property (nonatomic,copy)NSString *name;
@end
@implementation TestObject
- (NSUInteger)getAge{
    return 100;
}
-(void)setAge:(NSUInteger)age{
}
- (void)sleep{
}
@end
Clone this wiki locally