In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "example analysis of IMP function calls in OC Rumtime", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and study the "example analysis of IMP function calls in OC Rumtime".
The OC runtime (runtime) tests a function, class_replaceMethod, as follows:
IMP originalMethod;NSString * CustomUppercaseString (id SELF,SEL _ CMD) {NSLog (@ "BeginConverting.") ; NSString * result=originalMethod (SELF,_CMD); NSLog (@ "EndConverting.") ; return result;} Implementation:
-(void) runtimeTest {originalMethod= [NSString instanceMethodForSelector:@selector (uppercaseString)]; class_replaceMethod ([NSString class], @ selector (uppercaseString), (IMP) MyUppercaseString,NULL); NSString * slots @ "zhang lei"; NSLog (@ "uppercase:%@", [s uppercaseString]);}
An error is reported on the following line during operation:
NSString * result=originalMethod (SELF,_CMD)
① first prompted too many parameters, asked Baidu that IMP itself contains self and _ cmd two parameters, no longer need to display the parameters. Continue to report an error after removing the parameters.
② prompt cannot convert void * to id under ARC. There is still an error after shutting down ARC, and it still cannot be converted.
When I looked at the definition of IMP, I found this:
/ A pointer to the function of a method implementation. # if! OBJC_OLD_DISPATCH_PROTOTYPEStypedef void (* IMP) (void / * id, SEL,... * /); # elsetypedef id (* IMP) (id, SEL,...); # endif reports an error mainly because IMP takes the definition in if and returns void *, so it is suspected that the project compilation settings are incorrect. Continue to search Baidu and find the following:
"friends who use XCode6.X should pay special attention. You need to go to the build settings of the project and set the Enable Strict Checking of objc_msgSend Calls option of Apple LLVM 6.0-Preprocessing to NO, otherwise result = imp (clazz, sel); you will report an error!"
So it is set up according to the above, and it runs successfully. And after debugging, it is found that it is indeed Enable Strict Checking of objc_msgSend Calls that controls the value of OBJC_OLD_DISPATCH_PROTOTYPES.
The above is all the contents of the article "sample Analysis of IMP function calls in OC Rumtime". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.