In my Swift iOS project, I want to check whether is the valid url or not before requesting to server. I did earlier in Objective C code to check many elements like presence of www, http, https, :, etc to validate whether the right url or not. Do we have anything similar in Swift code?
I am expecting like this Obj C method.
- (BOOL) validateUrl: (NSString *) candidate {
NSString *urlRegEx =
@"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";
NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx];
return [urlTest evaluateWithObject:candidate];
}
Please suggest.