From 85f7739a1094049140807441bfdfe3b05f32b7a5 Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Fri, 25 Sep 2020 21:50:42 +0300 Subject: [PATCH] NSSet: add missing convenience initializer This initializer exists in the macOS version of Foundation --- Sources/Foundation/NSSet.swift | 4 ++++ Tests/Foundation/Tests/TestNSSet.swift | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Sources/Foundation/NSSet.swift b/Sources/Foundation/NSSet.swift index 07d300ecf9..7f2318d6de 100644 --- a/Sources/Foundation/NSSet.swift +++ b/Sources/Foundation/NSSet.swift @@ -86,6 +86,10 @@ open class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCodi self.init(array: [object]) } + public convenience init(objects elements: Any...) { + self.init(array: elements) + } + internal class func _objects(from aDecoder: NSCoder, allowDecodingNonindexedArrayKey: Bool = true) -> [NSObject] { guard aDecoder.allowsKeyedCoding else { preconditionFailure("Unkeyed coding is unsupported.") diff --git a/Tests/Foundation/Tests/TestNSSet.swift b/Tests/Foundation/Tests/TestNSSet.swift index b409dabe16..34edd05a18 100644 --- a/Tests/Foundation/Tests/TestNSSet.swift +++ b/Tests/Foundation/Tests/TestNSSet.swift @@ -26,6 +26,10 @@ class TestNSSet : XCTestCase { XCTAssertEqual(set5, set3) set5.add(2) XCTAssertNotEqual(set5, set3) + + let set6 = NSSet(objects: "foo", "bar") + XCTAssertEqual(set6.count, 2) + XCTAssertEqual(set2, set6) } func testInitWithSet() {