Search code examples
objective-cswiftuiwebviewios8uiwebviewdelegate

Compare NSURL scheme in Swift with a String


I was wondering if this is possible to do in swift and what it would be the way of doing it?

I just want to be able to compare? the scheme of my url to whatever string I want.. This is how I have been doing it in objc.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
        if ([request.URL.scheme isEqual: @"http"] || [request.URL.scheme isEqual:@"https"]) {
            return NO;
        }

    return YES;
} 

Solution

  • Use == in Swift instead of isEqual: or isEqualToString: in Objective-C

    if (request.URL.scheme == "http" || request.URL.scheme == "https") {