@@ -132,11 +132,6 @@ open class NSOrderedSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
132
132
return 0 ..< count
133
133
}
134
134
135
- /// Checks that an index is valid: 0 ≤ `index` ≤ `count`.
136
- internal func _validateIndex( _ index: Int , file: StaticString = #file, line: UInt = #line) {
137
- precondition ( index <= count && index >= 0 , " \( self ) : Index out of bounds " , file: file, line: line)
138
- }
139
-
140
135
/// Checks that an index is valid for subscripting: 0 ≤ `index` < `count`.
141
136
internal func _validateSubscript( _ index: Int , file: StaticString = #file, line: UInt = #line) {
142
137
precondition ( _indices. contains ( index) , " \( self ) : Index out of bounds " , file: file, line: line)
@@ -351,7 +346,7 @@ extension NSOrderedSet {
351
346
open class NSMutableOrderedSet : NSOrderedSet {
352
347
353
348
open func insert( _ object: Any , at idx: Int ) {
354
- _validateIndex ( idx)
349
+ precondition ( idx <= count && idx >= 0 , " \( self ) : Index out of bounds " )
355
350
356
351
let value = __SwiftValue. store ( object)
357
352
@@ -454,14 +449,18 @@ extension NSMutableOrderedSet {
454
449
}
455
450
}
456
451
452
+ /// Sets the object at the specified index of the mutable ordered set.
453
+ ///
454
+ /// - Parameters:
455
+ /// - obj: The object to be set.
456
+ /// - idx: The index. If the index is equal to `count`, then it appends
457
+ /// the object. Otherwise it replaces the object at the index with the
458
+ /// given object.
457
459
open func setObject( _ obj: Any , at idx: Int ) {
458
- _validateIndex ( idx)
459
- let object = __SwiftValue. store ( obj)
460
- _storage. insert ( object)
461
- if idx == _orderedStorage. count {
462
- _orderedStorage. append ( object)
460
+ if idx == count {
461
+ insert ( obj, at: idx)
463
462
} else {
464
- _orderedStorage [ idx] = object
463
+ replaceObject ( at : idx, with : obj )
465
464
}
466
465
}
467
466
0 commit comments