• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Create a NSURL as a way to validate urls - not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Create a NSURL as a way to validate urls - not working (From: Juanjo Conti <email@hidden>)
 >Re: Create a NSURL as a way to validate urls - not working (From: Mike Abdullah <email@hidden>)
 >Re: Create a NSURL as a way to validate urls - not working (From: Juanjo Conti <email@hidden>)
 >Re: Create a NSURL as a way to validate urls - not working (From: Jens Alfke <email@hidden>)
 >Re: Create a NSURL as a way to validate urls - not working (From: Mike Abdullah <email@hidden>)
 >Re: Create a NSURL as a way to validate urls - not working (From: Juanjo Conti <email@hidden>)

  • Prev by Date: Re: Mac OS X - AppDelegate applicationDidFinishLaunching
  • Next by Date: Re: Mac OS X - AppDelegate applicationDidFinishLaunching
  • Previous by thread: Re: Create a NSURL as a way to validate urls - not working
  • Next by thread: Inconvenient exception impossible to get rid of?
  • Index(es):
    • Date
    • Thread