Re: Create a NSURL as a way to validate urls - not working

2015-03-03 Thread Marco S Hyman

> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-03 Thread Juanjo Conti
Missing return type!!! Argh... caming from Python and Ruby doesn't help.
Thanks!!!

On Tue, Mar 3, 2015 at 12:27 PM, Roland King  wrote:

>
> On 3 Mar 2015, at 22:42, Juanjo Conti  wrote:
>
> Ok, first of all thanks all for the replies.
>
> I'm trying to solve it this an util class method:
>
> import Cocoa
>
> 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?
>
>
> Using Swift :)
>
> Thanks,
>
>
> If you use the latest beta you get a slightly better error message “Bool
> is not convertible to ()”, that is one thing that version has fixed, the
> $T3 variables in error messages, which is a good step forward.
>
> That error message might lead you to realise what I didn’t from the
> original error message either, that your function definition is missing
> “->Bool” to give it a return type. Would still prefer an error message
> which directly said ‘Incorrect return type” but at least this one gave
> enough hints to figure it out.
>
>


-- 

Juanjo Conti http://goog_2023646312>@carouselapps.com
>

Software Engineer - Carousel Apps 

-- 
Carousel Apps Limited, registered in England & Wales with registered number 
7689440 and registered office Unit 2 Artbrand Studios, 7 Leathermarket 
Street, London SE1 3HN. Any communication sent by or on behalf of Carousel 
App Ltd or any of its subsidiary, holding or affiliated companies or 
entities (together "Watu") is confidential and may be privileged or 
otherwise protected. If you receive it in error please inform us and then 
delete it from your system. You should not copy it or disclose its contents 
to anyone. Messages sent to and from Watu may be monitored to ensure 
compliance with our internal policies and to protect our business. Emails 
are not secure and cannot be guaranteed to be error free. Anyone who 
communicates with us by email is taken to accept these risks.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-03 Thread Roland King

> On 3 Mar 2015, at 22:42, Juanjo Conti  wrote:
> 
> Ok, first of all thanks all for the replies.
> 
> I'm trying to solve it this an util class method:
> 
> import Cocoa
> 
> 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?
> 

Using Swift :)

> Thanks,


If you use the latest beta you get a slightly better error message “Bool is not 
convertible to ()”, that is one thing that version has fixed, the $T3 variables 
in error messages, which is a good step forward. 

That error message might lead you to realise what I didn’t from the original 
error message either, that your function definition is missing “->Bool” to give 
it a return type. Would still prefer an error message which directly said 
‘Incorrect return type” but at least this one gave enough hints to figure it 
out. 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-03 Thread Juanjo Conti
Ok, first of all thanks all for the replies.

I'm trying to solve it this an util class method:

import Cocoa

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?

Thanks,

On Tue, Mar 3, 2015 at 6:19 AM, Mike Abdullah  wrote:

>
> On 3 Mar 2015, at 01:57, Jens Alfke  wrote:
>
>
> On Mar 2, 2015, at 3:55 PM, Juanjo Conti  wrote:
>
> Ok, I wanted to validate that the url is an absolute one. Is there
> something in Swift standard lib to do this?
>
>
> I typically check whether url.scheme is a non-nil, non-empty string. You
> may also want to check the scheme if you need to restrict input to HTTP
> URLs, for instance. (For example, “a:b” is a perfectly valid absolute URL,
> but probably not one your app will find useful.) Keep in mind that URL
> schemes are case-insensitive, so “HTTP:” means the same as “http:”.
>
> Also, this has nothing to do with the Swift library. NSURL is part of the
> Foundation framework, so this is independent of whether you’re using Swift
> or Objective-C.
>
>
> I’d say this is pretty good advice. The NSURL docs also used to mention an
> alternative, that you could test the -resourceSpecifier to see if it began
> with // as a pretty good test, but that’s no longer mentioned, which is
> intriguing.
>
>


-- 

Juanjo Conti http://goog_2023646312>@carouselapps.com
>

Software Engineer - Carousel Apps 

-- 
Carousel Apps Limited, registered in England & Wales with registered number 
7689440 and registered office Unit 2 Artbrand Studios, 7 Leathermarket 
Street, London SE1 3HN. Any communication sent by or on behalf of Carousel 
App Ltd or any of its subsidiary, holding or affiliated companies or 
entities (together "Watu") is confidential and may be privileged or 
otherwise protected. If you receive it in error please inform us and then 
delete it from your system. You should not copy it or disclose its contents 
to anyone. Messages sent to and from Watu may be monitored to ensure 
compliance with our internal policies and to protect our business. Emails 
are not secure and cannot be guaranteed to be error free. Anyone who 
communicates with us by email is taken to accept these risks.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-03 Thread Mike Abdullah

> On 3 Mar 2015, at 01:57, Jens Alfke  wrote:
> 
> 
>> On Mar 2, 2015, at 3:55 PM, Juanjo Conti > > wrote:
>> 
>> Ok, I wanted to validate that the url is an absolute one. Is there
>> something in Swift standard lib to do this?
> 
> I typically check whether url.scheme is a non-nil, non-empty string. You may 
> also want to check the scheme if you need to restrict input to HTTP URLs, for 
> instance. (For example, “a:b” is a perfectly valid absolute URL, but probably 
> not one your app will find useful.) Keep in mind that URL schemes are 
> case-insensitive, so “HTTP:” means the same as “http:”.
> 
> Also, this has nothing to do with the Swift library. NSURL is part of the 
> Foundation framework, so this is independent of whether you’re using Swift or 
> Objective-C.

I’d say this is pretty good advice. The NSURL docs also used to mention an 
alternative, that you could test the -resourceSpecifier to see if it began with 
// as a pretty good test, but that’s no longer mentioned, which is intriguing.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-02 Thread Jens Alfke

> On Mar 2, 2015, at 4:52 PM, Keary Suska  wrote:
> 
> That depends on what you mean by "validate." If you simply mean checking 
> whether it well-formed, you can do that easily with a regular expression 
> match, such as (written in email):
>   ^http://(?:[a-z0-9-]+\.){1,}[a-z]{2,4}

It’s really much better to ask the system frameworks to do this kind of 
checking/parsing, since they are more likely than you are to know all the 
nuances of the RFCs. For instance, your regex above won’t work with 
international domain names, or capitalized forms of domain names, or top-level 
domains longer than 4 characters, or single-component domains like “foo”...

(I’m not saying this to pick on you, just warning people who might come across 
this thread in a web-search and copy and paste your regex. I’m sure it would 
also take me a while to write a regex that could reliably match domain names, 
assuming I even decided to try; that’s part of my point.)

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-02 Thread Jens Alfke

> On Mar 2, 2015, at 3:55 PM, Juanjo Conti  wrote:
> 
> Ok, I wanted to validate that the url is an absolute one. Is there
> something in Swift standard lib to do this?

I typically check whether url.scheme is a non-nil, non-empty string. You may 
also want to check the scheme if you need to restrict input to HTTP URLs, for 
instance. (For example, “a:b” is a perfectly valid absolute URL, but probably 
not one your app will find useful.) Keep in mind that URL schemes are 
case-insensitive, so “HTTP:” means the same as “http:”.

Also, this has nothing to do with the Swift library. NSURL is part of the 
Foundation framework, so this is independent of whether you’re using Swift or 
Objective-C.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-02 Thread Keary Suska
On Mar 2, 2015, at 4:55 PM, Juanjo Conti  wrote:

> Ok, I wanted to validate that the url is an absolute one. Is there
> something in Swift standard lib to do this?

That depends on what you mean by "validate." If you simply mean checking 
whether it well-formed, you can do that easily with a regular expression match, 
such as (written in email):
^http://(?:[a-z0-9-]+\.){1,}[a-z]{2,4}

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-02 Thread Uli Kusterer
I think you want NSURLComponents.

> On 03 Mar 2015, at 00:55, Juanjo Conti  wrote:
> 
> Ok, I wanted to validate that the url is an absolute one. Is there
> something in Swift standard lib to do this?
> 
> Thanks in advance!
> 
> On Mon, Mar 2, 2015 at 7:46 PM, Mike Abdullah  wrote:
> 
>> 
>>> On 2 Mar 2015, at 23:22, Juanjo Conti  wrote:
>>> 
>>> According the docs (
>>> 
>> https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/
>> )
>>> NSURL(string: aString) will return nil if aString is malformed.
>>> 
>>> But I've tried this in the a playground and no nil is returned:
>>> 
>>> NSURL(string: "")!
>>> NSURL(string: "")!
>>> 
>>> Why is this? are the docs wrong?
>> 
>> Go read the specs NSURL references. An empty string and “” are both
>> valid by its definition.
>> 
>> Pretty much all NSURL is looking for is you’re not using any unsupported
>> characters, or mis-using reserved characters. Anything more, and you’ve got
>> to test the resulting URL yourself. Perhaps you can elaborate what you
>> consider to be a valid URL in your case.
>> 
>> 
> 
> 
> -- 
> 
> Juanjo Conti http://goog_2023646312>@carouselapps.com
> >
> 
> Software Engineer - Carousel Apps 
> 
> -- 
> Carousel Apps Limited, registered in England & Wales with registered number 
> 7689440 and registered office Unit 2 Artbrand Studios, 7 Leathermarket 
> Street, London SE1 3HN. Any communication sent by or on behalf of Carousel 
> App Ltd or any of its subsidiary, holding or affiliated companies or 
> entities (together "Watu") is confidential and may be privileged or 
> otherwise protected. If you receive it in error please inform us and then 
> delete it from your system. You should not copy it or disclose its contents 
> to anyone. Messages sent to and from Watu may be monitored to ensure 
> compliance with our internal policies and to protect our business. Emails 
> are not secure and cannot be guaranteed to be error free. Anyone who 
> communicates with us by email is taken to accept these risks.
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/witness.of.teachtext%40gmx.net
> 
> This email sent to witness.of.teacht...@gmx.net

Cheers,
-- Uli Kusterer
“The Witnesses of TeachText are everywhere...”
http://zathras.de


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-02 Thread Juanjo Conti
Ok, I wanted to validate that the url is an absolute one. Is there
something in Swift standard lib to do this?

Thanks in advance!

On Mon, Mar 2, 2015 at 7:46 PM, Mike Abdullah  wrote:

>
> > On 2 Mar 2015, at 23:22, Juanjo Conti  wrote:
> >
> > According the docs (
> >
> https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/
> )
> > NSURL(string: aString) will return nil if aString is malformed.
> >
> > But I've tried this in the a playground and no nil is returned:
> >
> > NSURL(string: "")!
> > NSURL(string: "")!
> >
> > Why is this? are the docs wrong?
>
> Go read the specs NSURL references. An empty string and “” are both
> valid by its definition.
>
> Pretty much all NSURL is looking for is you’re not using any unsupported
> characters, or mis-using reserved characters. Anything more, and you’ve got
> to test the resulting URL yourself. Perhaps you can elaborate what you
> consider to be a valid URL in your case.
>
>


-- 

Juanjo Conti http://goog_2023646312>@carouselapps.com
>

Software Engineer - Carousel Apps 

-- 
Carousel Apps Limited, registered in England & Wales with registered number 
7689440 and registered office Unit 2 Artbrand Studios, 7 Leathermarket 
Street, London SE1 3HN. Any communication sent by or on behalf of Carousel 
App Ltd or any of its subsidiary, holding or affiliated companies or 
entities (together "Watu") is confidential and may be privileged or 
otherwise protected. If you receive it in error please inform us and then 
delete it from your system. You should not copy it or disclose its contents 
to anyone. Messages sent to and from Watu may be monitored to ensure 
compliance with our internal policies and to protect our business. Emails 
are not secure and cannot be guaranteed to be error free. Anyone who 
communicates with us by email is taken to accept these risks.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-02 Thread Mike Abdullah

> On 2 Mar 2015, at 23:22, Juanjo Conti  wrote:
> 
> According the docs (
> https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/)
> NSURL(string: aString) will return nil if aString is malformed.
> 
> But I've tried this in the a playground and no nil is returned:
> 
> NSURL(string: "")!
> NSURL(string: "")!
> 
> Why is this? are the docs wrong?

Go read the specs NSURL references. An empty string and “” are both valid 
by its definition.

Pretty much all NSURL is looking for is you’re not using any unsupported 
characters, or mis-using reserved characters. Anything more, and you’ve got to 
test the resulting URL yourself. Perhaps you can elaborate what you consider to 
be a valid URL in your case.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Create a NSURL as a way to validate urls - not working

2015-03-02 Thread pscott

On 3/2/2015 2:22 PM, Juanjo Conti wrote:

According the docs (
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/)
NSURL(string: aString) will return nil if aString is malformed.

But I've tried this in the a playground and no nil is returned:

NSURL(string: "")!
NSURL(string: "")!

Why is this? are the docs wrong?

Thanks in advance,
The doc also states the URL format string conforms to RFC2396, which 
defines the term "relative URI reference". That's what you are providing 
in this case, a relative URI reference; even a blank relative URI 
reference is allowed.


Paul



smime.p7s
Description: S/MIME Cryptographic Signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Create a NSURL as a way to validate urls - not working

2015-03-02 Thread Juanjo Conti
According the docs (
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/)
NSURL(string: aString) will return nil if aString is malformed.

But I've tried this in the a playground and no nil is returned:

NSURL(string: "")!
NSURL(string: "")!

Why is this? are the docs wrong?

Thanks in advance,
-- 

Juanjo Conti http://goog_2023646312>@carouselapps.com
>

Software Engineer - Carousel Apps 

-- 
Carousel Apps Limited, registered in England & Wales with registered number 
7689440 and registered office Unit 2 Artbrand Studios, 7 Leathermarket 
Street, London SE1 3HN. Any communication sent by or on behalf of Carousel 
App Ltd or any of its subsidiary, holding or affiliated companies or 
entities (together "Watu") is confidential and may be privileged or 
otherwise protected. If you receive it in error please inform us and then 
delete it from your system. You should not copy it or disclose its contents 
to anyone. Messages sent to and from Watu may be monitored to ensure 
compliance with our internal policies and to protect our business. Emails 
are not secure and cannot be guaranteed to be error free. Anyone who 
communicates with us by email is taken to accept these risks.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com