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

StackOverflow https://stackoverflow.com/questions/23373040

質問

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

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top