Runtime
Run-time Use:
1. KVO, KVC
2. The implementation of the exchange of two methods in the process of operation, the method of changing the system.
For example: When a project has been done for several years from IOS6 to IOS7, to replace the previous picture, you can expand the uiimage to achieve its classification. Add a class method Imagewithname:name. Then the system imagename: The Imagewithname:name method and the method are replaced at run time without modifying other code.
#import "Uiimage+extension.h"#import<objc/runtime.h>@implement UIImage (Extension)+(void) load{Method Othermethod= Class_getclassmethod ([UIImageclass], @selector (imagewithname:)); Method Originmethod= Class_getclassmethod ([UIImageclass], @selector (imagenamed:)); //implementation of Exchange two methodsmethod_exchangeimplementations (Othermethod, Originmethod);}+ (UIImage *) Imagewithname: (NSString *) name{BOOL iOS7= [[Uidevice currentdevice].systemversion Floatvalue] >=7.0; UIImage* Image =Nil; if(IOS7) {NSString* NewName = [name stringbyappendingstring:@"_os7"]; Image=[UIImage Imagewithname:newname]; } if(Image = =Nil) {Image=[UIImage Imagewithname:name]; } returnimage;}@end
Runtime for IOS