[swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Zhao Xin via swift-users
As you can see, `URL` is not equal but the `path` is. I wonder why urls do not equal here? let url = URL(fileURLWithPath: "foo/bar", isDirectory: false) let baseURL = url.deletingLastPathComponent() let newURL = URL(fileURLWithPath: "bar", isDirectory: false, relativeTo: baseURL) print(url ==

[swift-users] Memory Leak Indicated when Derived from NSObject

2016-10-14 Thread Chris Chirogene via swift-users
Xcode8 is showing a memory leak in instruments and the memory graph. I have narrowed it down to this: deriving from NSObject produces a leak indication. I have no idea why. I need an NSObject to later use the @objc directive. The Test instance stored in the mDict Dictionary is indicated as a leak

[swift-users] Coerce NSData to Data

2016-10-14 Thread Ryan Lovelett via swift-users
I'm puzzeled by the behavior of the automatic coercion. Specifically when something will work and when it will not. It at least has something to do with the platform. That much I have tracked down. I've attached a file, bridge.swift, that on Linux will fail to compile with the error: cannot conver

Re: [swift-users] Overload by return type optionality?

2016-10-14 Thread Luis Ferro via swift-users
It may also work if you create a "generic" extension that can only be applied to strings. Then i'm guessing that you will not need to specify the type on the use. LF On 13/10/2016 22:44, Nevin Brackett-Rozinsky via swift-users wrote: It works if you specify the types of the variables: let

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Greg Parker via swift-users
> On Oct 14, 2016, at 7:33 AM, Zhao Xin via swift-users > wrote: > > As you can see, `URL` is not equal but the `path` is. I wonder why urls do > not equal here? > > let url = URL(fileURLWithPath: "foo/bar", isDirectory: false) > let baseURL = url.deletingLastPathComponent() > let newURL = UR

Re: [swift-users] Coerce NSData to Data

2016-10-14 Thread Joe Groff via swift-users
> On Oct 14, 2016, at 11:15 AM, Ryan Lovelett via swift-users > wrote: > > I'm puzzeled by the behavior of the automatic coercion. Specifically > when something will work and when it will not. It at least has something > to do with the platform. That much I have tracked down. > > I've attached

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread zh ao via swift-users
In your opinion, `baseURL` is a factor more important than `path`. I can not unaccept your answer. But I want to know why? Is there a standard on URL equality?  ZhaoXin  Get Outlook for iOS _ From: Greg Parker Sent: 星期六, 十月 15, 2016 05:40 Subject: Re

[swift-users] Will it be better if `fallthrough` works with `label` in nested `switch - case`?

2016-10-14 Thread Zhao Xin via swift-users
I thought below code would work. It didn't. let count = 1 outerSwitch: switch count { case 0, 1: let buttonId = 0 switch buttonId { case NSAlertFirstButtonReturn: print("do something") case NSAlertSecondButtonReturn: print("do something") case NSAlert

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Jens Alfke via swift-users
> On Oct 14, 2016, at 5:16 PM, zh ao via swift-users > wrote: > > In your opinion, `baseURL` is a factor more important than `path`. I can not > unaccept your answer. But I want to know why? Is there a standard on URL > equality? I think this is just a weirdness of NSURL (assuming you’re ru

Re: [swift-users] Will it be better if `fallthrough` works with `label` in nested `switch - case`?

2016-10-14 Thread Zhao Xin via swift-users
I manage to use below work around. let count = 1 switch count { case 0, 1: let buttonId = NSAlertThirdButtonReturn let shouldFallthrough = { () -> Bool in switch buttonId { case NSAlertFirstButtonReturn: print("do something") case NSAlertSecondB

Re: [swift-users] Will it be better if `fallthrough` works with `label` in nested `switch - case`?

2016-10-14 Thread Saagar Jha via swift-users
This seems like a better solution to me. The other one smacks of goto. On Fri, Oct 14, 2016 at 20:52 Zhao Xin via swift-users < swift-users@swift.org> wrote: > I manage to use below work around. > > let count = 1 > > > switch count { > > case 0, 1: > > let buttonId = NSAlertThirdButtonReturn >

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Zhao Xin via swift-users
You are right Jens. If I use `appendingPathComponent`, it works. let url = URL(fileURLWithPath: "foo/bar", isDirectory: false) let baseURL = url.deletingLastPathComponent() let newURL = URL(fileURLWithPath: "bar", isDirectory: false, relativeTo: baseURL) let testURL = baseURL.appendingPathCompo

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Keith Smiley via swift-users
Just want to mention that there are some differences between `NSURL` and `URL`. Here's an example from the repl: ``` 1> import Foundation 2> NSURL(string: "") $R0: NSURL? = "" { ObjectiveC.NSObject = {} } 3> URL(string: "") $R1: URL? = nil ``` -- Keith Smiley On 10/14, Jens Alfke via swi

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Keith Smiley via swift-users
FWIW we've overridden URL's equality function in order to get a "more realistic" result. We lowercase everything and compare the scheme, host, port, and query, along with normalizing the path to handle cases where `/` exists in some paths but doesn't in others. This solves this problem as well: ``

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Jens Alfke via swift-users
> On Oct 14, 2016, at 10:20 PM, Keith Smiley wrote: > > FWIW we've overridden URL's equality function in order to get a "more > realistic" > result. We lowercase everything and compare the scheme, host, port, and query, I hope you don’t lowercase everything — the scheme and host are case-inse

Re: [swift-users] Why can't we get `URL` equal on the same path?

2016-10-14 Thread Keith Smiley via swift-users
In our case, if we accidentally send a URL from the server with a trailing slash, we want that to be equivalent to one without. But yea, if you're manipulating it you might have more problems! Although in our case we add the slash for the case without it. -- Keith Smiley On 10/14, Jens Alfke wrot