IOS 12 Learning Series: Warnings for Xcode ignore elimination processing

Source: Internet
Author: User

Problem description

The HTML code is as follows

1 <HTML>2     <Head>3         <MetaCharSet= "Utf-8"/>4         <title>My Web page</title>5         <Scripttype= "Text/javascript">6             functionjs2oc ()7             {8 window.location.href="Fzw://send";9             }Ten         </Script> One     </Head> A     <Body> -         <inputvalue= "JS call oc"type= "button"onclick= ' js2oc (); '></input> -     </Body> the </HTML>

The display effect is as follows

The OC code is as follows

1 /**2 * Jump to Judge3  */4-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (Nsurlrequest *Request Navigationtype: (uiwebviewnavigationtype) Navigationtype5 {6NSString *urlstring =request. url.absolutestring;7NSLog (@"urlstring:%@", urlstring);8NSString *prestring =@"fzw://";9     if([urlstring hasprefix:prestring])Ten     { OneNSString *methodstring =[URLString substringFromIndex:preString.length]; ANSLog (@"methodstring:%@", methodstring); - [Self performselector:nsselectorfromstring (methodstring)]; -         returnNO; the     } -     returnYES; - } -  +-(void) Send - { +NSLog (@"%s", __func__); A}

Click on the demo.html button "JS call oc", the webpage jumps to fzw://send. UIWebView Proxy Method-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) request Navigationtype: (uiwebviewnavigationtype) Navigationtype intercept page and get web link fzw://send, after processing, finally call OC Specify Method-(void) Send, and return no cancel jump, so as to achieve JS call oc method.

But Xcode hint warning: performselector may cause a leak because it selector is unknown

Problem analysis

Compiler warnings are useful information for developers, but sometimes the compiler's IQ is too low to hint at unnecessary warnings. When some warnings do not want to be seen, you can use the following code to eliminate the warning.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-W warning name"
Code to close the warning
#pragma clang diagnostic pop

Problem solving

The name of the warning is-warc-performselector-leaks

1 /**2 * Jump to Judge3  */4-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (Nsurlrequest *Request Navigationtype: (uiwebviewnavigationtype) Navigationtype5 {6NSString *urlstring =request. url.absolutestring;7NSLog (@"urlstring:%@", urlstring);8NSString *prestring =@"fzw://";9     if([urlstring hasprefix:prestring])Ten     { OneNSString *methodstring =[URLString substringFromIndex:preString.length]; ANSLog (@"methodstring:%@", methodstring); - #pragmaClang Diagnostic push - #pragmaClang diagnostic ignored "-warc-performselector-leaks" the [Self performselector:nsselectorfromstring (methodstring)]; - #pragmaClang Diagnostic Pop -         returnNO; -     } +     returnYES; - } +  A-(void) Send at { -NSLog (@"%s", __func__); -}

IOS 12 Learning Series: Warnings for Xcode ignore elimination processing

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.