File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -144,8 +144,21 @@ extension NSOrderedSet {
144
144
return false
145
145
}
146
146
147
- public func intersectsOrderedSet( other: NSOrderedSet ) -> Bool { NSUnimplemented ( ) }
148
- public func intersectsSet( set: Set < NSObject > ) -> Bool { NSUnimplemented ( ) }
147
+ public func intersectsOrderedSet( other: NSOrderedSet ) -> Bool {
148
+ if count < other. count {
149
+ return contains { obj in other. containsObject ( obj as! NSObject ) }
150
+ } else {
151
+ return other. contains { obj in containsObject ( obj) }
152
+ }
153
+ }
154
+
155
+ public func intersectsSet( set: Set < NSObject > ) -> Bool {
156
+ if count < set. count {
157
+ return contains { obj in set. contains ( obj as! NSObject ) }
158
+ } else {
159
+ return set. contains { obj in containsObject ( obj) }
160
+ }
161
+ }
149
162
150
163
public func isSubsetOfOrderedSet( other: NSOrderedSet ) -> Bool {
151
164
return !self . contains { obj in
Original file line number Diff line number Diff line change @@ -250,14 +250,19 @@ class TestNSOrderedSet : XCTestCase {
250
250
func test_Intersection( ) {
251
251
let set = NSMutableOrderedSet ( arrayLiteral: " foo " . bridge ( ) , " bar " . bridge ( ) , " baz " . bridge ( ) )
252
252
let otherSet = NSOrderedSet ( array: [ " foo " , " baz " ] . bridge ( ) . bridge ( ) )
253
+ XCTAssert ( set. intersectsOrderedSet ( otherSet) )
253
254
let otherOtherSet = Set ( [ " foo " . bridge ( ) , " 123 " . bridge ( ) ] )
255
+ XCTAssert ( set. intersectsSet ( otherOtherSet) )
254
256
set. intersectOrderedSet ( otherSet)
255
257
XCTAssertEqual ( set. count, 2 )
256
258
XCTAssertEqual ( set [ 0 ] as? NSString , " foo " )
257
259
XCTAssertEqual ( set [ 1 ] as? NSString , " baz " )
258
260
set. intersectSet ( otherOtherSet)
259
261
XCTAssertEqual ( set. count, 1 )
260
262
XCTAssertEqual ( set [ 0 ] as? NSString , " foo " )
263
+
264
+ let nonIntersectingSet = Set ( [ " asdf " . bridge ( ) ] )
265
+ XCTAssertFalse ( set. intersectsSet ( nonIntersectingSet) )
261
266
}
262
267
263
268
func test_Subtraction( ) {
You can’t perform that action at this time.
0 commit comments