[swift-corelibs-dev] Equality, etc in Foundation

Luke Howard lukeh at padl.com
Wed Dec 30 01:15:32 CST 2015

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 == 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 :)

— Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20151230/92822062/attachment.html>

More information about the swift-corelibs-dev mailing list