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() {