Re: Create a NSURL as a way to validate urls - not working
Re: Create a NSURL as a way to validate urls - not working
- Subject: Re: Create a NSURL as a way to validate urls - not working
- From: Marco S Hyman <email@hidden>
- Date: Tue, 03 Mar 2015 09:38:49 -0800
> class Utils: NSObject {
>
> class func isValidUrl(url: NSURL?) {
> var lower = url?.scheme?.lowercaseString
> return lower == "http" || lower == "https"
> }
> }
> Sadly I'm getting and error in the return line that I can't interprete:
> Cannot invoke == with argument list of type `($T4, $T8)`
>
> What I'm doing wrong?
You didn't specify the return type of the function.
lower is an optional and may be nul.
Why is it a class function?
Try it this way using a global function
func isValidUrl(url: NSURL?) -> Bool {
if let lower = url?.scheme?.lowercaseString {
return lower == "http" || lower == "https"
}
return false
}
let foo = NSURL(string: "some/string")
let bar = NSURL(string: "http://some/string")
isValidUrl(foo) // false
isValidUrl(bar) // true
I'd also rename the the function to hasHTTPScheme or something similar.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden