Skip to content

Commit 618f82d

Browse files
authored
Merge pull request #644 from saiHemak/nssetcrash-branch
2 parents 31ce31b + 20ba9bd commit 618f82d

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Foundation/Set.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ extension Set : _ObjectTypeBridgeable {
4040
if let o = obj as? Element {
4141
set.insert(o)
4242
} else {
43-
failedConversion = true
44-
stop.pointee = true
43+
// here obj must be a swift type
44+
if let nsObject = _SwiftValue.store(obj) as? Element {
45+
set.insert(nsObject)
46+
} else {
47+
failedConversion = true
48+
stop.pointee = true
49+
}
4550
}
4651
}
4752
} else if type(of: source) == _NSCFSet.self {

TestFoundation/TestNSSet.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class TestNSSet : XCTestCase {
3535
("test_CountedSetObjectCount", test_CountedSetObjectCount),
3636
("test_CountedSetAddObject", test_CountedSetAddObject),
3737
("test_CountedSetRemoveObject", test_CountedSetRemoveObject),
38-
("test_CountedSetCopying", test_CountedSetCopying)
38+
("test_CountedSetCopying", test_CountedSetCopying),
39+
("test_mutablesetWithDictionary", test_mutablesetWithDictionary),
3940
]
4041
}
4142

@@ -226,5 +227,13 @@ class TestNSSet : XCTestCase {
226227
XCTAssertTrue(NSArray(array: setMutableCopy.allObjects).index(of: entry) != NSNotFound)
227228
}
228229
}
229-
230+
231+
func test_mutablesetWithDictionary() {
232+
let aSet = NSMutableSet()
233+
let dictionary = NSMutableDictionary()
234+
let key = NSString(string: "Hello")
235+
aSet.add(["world": "again"])
236+
dictionary.setObject(aSet, forKey: key)
237+
XCTAssertNotNil(dictionary.description) //should not crash
238+
}
230239
}

0 commit comments

Comments
 (0)