Runtime for IOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.