Equality, etc in Foundation


(Luke Howard) #1

Whilst implementing XCTests for NSKeyedUnarchiver, I noticed some issues with equality.
Let’s say I have the following simple Swift program:

    import SwiftFoundation
    
    let url1 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com"))!
    let url2 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com"))!
    
    print("\(url1.isEqual(url2))")
    print("\(url1 == url2)")

It returns false for both, as opposed to true on OS X Foundation.

NSObject() implements Equatable in terms of isEqual; that’s fine, but apart from __NSCFType the bridged types do not implement isEqual:. It seems that hash, isEqual and description need to be pasted in for the bridged types, à la CF_CLASSIMPLEMENTATION.

I feel though I may be missing something – I would have thought TestFoundation would depend on the equality operator working :slight_smile:

— Luke


(Luke Howard) #2

Proposed fix:

https://github.com/lhoward/swift-corelibs-foundation/commit/fe5dcce6ccf06d2f5b8e85c792012dbaee8f59f7

Also tracking in [SR-414].

···

On 30 Dec 2015, at 6:15 PM, Luke Howard via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

    import SwiftFoundation
    
    let url1 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com <https://www.example.com/>"))!
    let url2 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com <https://www.example.com/>"))!
    
    print("\(url1.isEqual(url2))")
    print("\(url1 == url2)")

--
www.lukehoward.com
soundcloud.com/lukehoward


(Tony Parker) #3

Hi Luke,

Your proposed fix seems reasonable to me. Did you submit it as a PR too?

Thanks,
- Tony

···

On Dec 29, 2015, at 11:28 PM, Luke Howard via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Proposed fix:

https://github.com/lhoward/swift-corelibs-foundation/commit/fe5dcce6ccf06d2f5b8e85c792012dbaee8f59f7

Also tracking in [SR-414].

On 30 Dec 2015, at 6:15 PM, Luke Howard via swift-corelibs-dev <swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>> wrote:

    import SwiftFoundation
    
    let url1 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com <https://www.example.com/>"))!
    let url2 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com <https://www.example.com/>"))!
    
    print("\(url1.isEqual(url2))")
    print("\(url1 == url2)")

--
www.lukehoward.com <http://www.lukehoward.com/>
soundcloud.com/lukehoward

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Philippe Hausler) #4

Actually I think we already got this one integrated.

···

On Jan 4, 2016, at 12:58 PM, Tony Parker via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hi Luke,

Your proposed fix seems reasonable to me. Did you submit it as a PR too?

Thanks,
- Tony

On Dec 29, 2015, at 11:28 PM, Luke Howard via swift-corelibs-dev <swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>> wrote:

Proposed fix:

https://github.com/lhoward/swift-corelibs-foundation/commit/fe5dcce6ccf06d2f5b8e85c792012dbaee8f59f7

Also tracking in [SR-414].

On 30 Dec 2015, at 6:15 PM, Luke Howard via swift-corelibs-dev <swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>> wrote:

    import SwiftFoundation
    
    let url1 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com <https://www.example.com/>"))!
    let url2 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com <https://www.example.com/>"))!
    
    print("\(url1.isEqual(url2))")
    print("\(url1 == url2)")

--
www.lukehoward.com <http://www.lukehoward.com/>
soundcloud.com/lukehoward <http://soundcloud.com/lukehoward>

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Tony Parker) #5

Cool, thanks Philippe and Luke!

- Tony

···

On Jan 4, 2016, at 12:59 PM, Philippe Hausler <phausler@apple.com> wrote:

Actually I think we already got this one integrated.

On Jan 4, 2016, at 12:58 PM, Tony Parker via swift-corelibs-dev <swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>> wrote:

Hi Luke,

Your proposed fix seems reasonable to me. Did you submit it as a PR too?

Thanks,
- Tony

On Dec 29, 2015, at 11:28 PM, Luke Howard via swift-corelibs-dev <swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>> wrote:

Proposed fix:

https://github.com/lhoward/swift-corelibs-foundation/commit/fe5dcce6ccf06d2f5b8e85c792012dbaee8f59f7

Also tracking in [SR-414].

On 30 Dec 2015, at 6:15 PM, Luke Howard via swift-corelibs-dev <swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>> wrote:

    import SwiftFoundation
    
    let url1 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com <https://www.example.com/>"))!
    let url2 = NSURL(string: "foo.xml", relativeToURL:NSURL(string: "https://www.example.com <https://www.example.com/>"))!
    
    print("\(url1.isEqual(url2))")
    print("\(url1 == url2)")

--
www.lukehoward.com <http://www.lukehoward.com/>
soundcloud.com/lukehoward <http://soundcloud.com/lukehoward>

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev