Skip to content

[SR-4242] Add NSMutableOrderedSet subscript setter that is missing from non-Darwin #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Foundation/NSOrderedSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@ open class NSMutableOrderedSet : NSOrderedSet {
_storage.remove(value)
_orderedStorage.remove(at: index(of: object))
}

open override subscript(idx: Int) -> Any {
get {
return object(at: idx)
}
set {
replaceObject(at: idx, with: newValue)
}
}

}

extension NSMutableOrderedSet {
Expand Down
3 changes: 2 additions & 1 deletion TestFoundation/TestNSOrderedSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ class TestNSOrderedSet : XCTestCase {
func test_ReplaceObject() {
let set = NSMutableOrderedSet(arrayLiteral: "foo", "bar", "baz")
set.replaceObject(at: 1, with: "123")
set[2] = "456"
XCTAssertEqual(set.count, 3)
XCTAssertEqual(set[0] as? String, "foo")
XCTAssertEqual(set[1] as? String, "123")
XCTAssertEqual(set[2] as? String, "baz")
XCTAssertEqual(set[2] as? String, "456")
}

func test_ExchangeObjects() {
Expand Down