Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: Format specifies type 'long' but the argument has type 'UIWebViewNavigationType' ( aka 'enum UIWebViewNavigationType')

Was wondering if someone can help me with this error warning which I am receiving in Xcode. I think it has something to do with 32 v 64bit. I would like the code to work in both 32 and 64bit. The relevant section of code is:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"expected:%ld, got:%ld", (long)UIWebViewNavigationTypeLinkClicked, navigationType);
    NSLog(@"Main Doc URL:%@", [[request mainDocumentURL] absoluteString]);
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        [[UIApplication sharedApplication] openURL:[request mainDocumentURL]];
        return NO;

many thanks

like image 996
william higham Avatar asked Dec 12 '22 06:12

william higham


1 Answers

UIWebViewNavigationType is defined as

typedef NS_ENUM(NSInteger, UIWebViewNavigationType) {
    // ...
};

and NSInteger is int on 32-bit and long on 64-bit platforms. Therefore you should cast the value to long

NSLog(@"expected:%ld, got:%ld", (long)UIWebViewNavigationTypeLinkClicked,
                                (long)navigationType);

to make it compile without warnings (and work correctly) in all cases.

like image 83
Martin R Avatar answered Mar 30 '23 00:03

Martin R