I need to intercept a URL and go outside the WebView if the URL contains MAPS or DOCUMENTS constants. I must also go outside if url does not contain the value of DOMAIN and LOGIN_SALES_FORCE.This is working nice, but seems ugly for me. Any ideas?if ([request.URL.absoluteString rangeOfString:MAPS      ].location != NSNotFound ||    [request.URL.absoluteString rangeOfString:DOCUMENTS ].location != NSNotFound){    NSURL *url = [NSURL URLWithString:request.URL.absoluteString];    return [[UIApplication sharedApplication] openURL:url];} else if ([request.URL.absoluteString rangeOfString:DOMINIO           ].location == NSNotFound &&           [request.URL.absoluteString rangeOfString:LOGIN_SALES_FORCE ].location == NSNotFound) {    NSURL *url = [NSURL URLWithString:request.URL.absoluteString];    return [[UIApplication sharedApplication] openURL:url];}
Intercept URL containing values or not
objective c;url
Disclaimer: I don't know Objective-C. The proposed changes are quite basic, though, and should give the same result as your original code.Intermediate variablesTo shorten your expressions, you may want to use an intermediate variable:NSString *absUrl = request.URL.absoluteString;Then, you can group your conditions using boolean operators.Boolean logicif (   [absUrl rangeOfString:MAPS].location != NSNotFound     || [absUrl rangeOfString:DOCUMENTS].location != NSNotFound    || (    [absUrl rangeOfString:DOMINIO].location == NSNotFound         && [absUrl rangeOfString:LOGIN_SALES_FORCE].location == NSNotFound)){    NSURL *url = [NSURL URLWithString:request.URL.absoluteString];    return [[UIApplication sharedApplication] openURL:url];}RemarksReading this documentation, I find it strange that you are converting request.URL to url using URLWithString. I may be wrong, but you could use absoluteUrl to achieve the same effect.