Skip to content

Commit 8f251a9

Browse files
committed
NSMutableArray: Rename methods to match Darwin
- addObjectsFromArray() -> addObjects(from:) - replaceObjects(in:withObjectsFromArray) -> replaceObjects(in:withObjectsFrom:) - sort() -> sort(comparator:)
1 parent 84bc0e7 commit 8f251a9

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

Foundation/NSArray.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ open class NSMutableArray : NSArray {
715715
}
716716
}
717717

718-
open func addObjectsFromArray(_ otherArray: [Any]) {
718+
open func addObjects(from otherArray: [Any]) {
719719
if type(of: self) === NSMutableArray.self {
720720
_storage += otherArray.map { _SwiftValue.store($0) as AnyObject }
721721
} else {
@@ -794,10 +794,10 @@ open class NSMutableArray : NSArray {
794794
open func replaceObjects(in range: NSRange, withObjectsFrom otherArray: [Any], range otherRange: NSRange) {
795795
var list = [Any]()
796796
otherArray._bridgeToObjectiveC().getObjects(&list, range:otherRange)
797-
replaceObjects(in: range, withObjectsFromArray:list)
797+
replaceObjects(in: range, withObjectsFrom: list)
798798
}
799799

800-
open func replaceObjects(in range: NSRange, withObjectsFromArray otherArray: [Any]) {
800+
open func replaceObjects(in range: NSRange, withObjectsFrom otherArray: [Any]) {
801801
if type(of: self) === NSMutableArray.self {
802802
_storage.reserveCapacity(count - range.length + otherArray.count)
803803
for idx in 0..<range.length {
@@ -815,7 +815,7 @@ open class NSMutableArray : NSArray {
815815
if type(of: self) === NSMutableArray.self {
816816
_storage = otherArray.map { _SwiftValue.store($0) }
817817
} else {
818-
replaceObjects(in: NSMakeRange(0, count), withObjectsFromArray: otherArray)
818+
replaceObjects(in: NSMakeRange(0, count), withObjectsFrom: otherArray)
819819
}
820820
}
821821

@@ -844,7 +844,7 @@ open class NSMutableArray : NSArray {
844844
for countedRange in indexes.rangeView {
845845
let range = NSMakeRange(countedRange.lowerBound, countedRange.upperBound - countedRange.lowerBound)
846846
let subObjects = objects[objectIndex..<objectIndex + range.length]
847-
self.replaceObjects(in: range, withObjectsFromArray: Array(subObjects))
847+
self.replaceObjects(in: range, withObjectsFrom: Array(subObjects))
848848
objectIndex += range.length
849849
}
850850
}
@@ -853,8 +853,8 @@ open class NSMutableArray : NSArray {
853853
self.setArray(self.sortedArray(compare, context: context))
854854
}
855855

856-
open func sort(_ cmptr: Comparator) {
857-
self.sort(options: [], usingComparator: cmptr)
856+
open func sort(comparator: Comparator) {
857+
self.sort(options: [], usingComparator: comparator)
858858
}
859859

860860
open func sort(options opts: NSSortOptions, usingComparator cmptr: Comparator) {

Foundation/NSCFArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,5 @@ internal func _CFSwiftArrayRemoveAllValues(_ array: AnyObject) {
126126

127127
internal func _CFSwiftArrayReplaceValues(_ array: AnyObject, _ range: CFRange, _ newValues: UnsafeMutablePointer<Unmanaged<AnyObject>>, _ newCount: CFIndex) {
128128
NSUnimplemented()
129-
// (array as! NSMutableArray).replaceObjectsInRange(NSMakeRange(range.location, range.length), withObjectsFromArray: newValues.array(newCount))
129+
// (array as! NSMutableArray).replaceObjectsInRange(NSMakeRange(range.location, range.length), withObjectsFrom: newValues.array(newCount))
130130
}

TestFoundation/TestNSArray.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class TestNSArray : XCTestCase {
2929
("test_objectAtIndex", test_objectAtIndex),
3030
("test_binarySearch", test_binarySearch),
3131
("test_binarySearchFringeCases", test_binarySearchFringeCases),
32-
("test_replaceObjectsInRange_withObjectsFromArray", test_replaceObjectsInRange_withObjectsFromArray),
33-
("test_replaceObjectsInRange_withObjectsFromArray_range", test_replaceObjectsInRange_withObjectsFromArray_range),
32+
("test_replaceObjectsInRange_withObjectsFrom", test_replaceObjectsInRange_withObjectsFrom),
33+
("test_replaceObjectsInRange_withObjectsFrom_range", test_replaceObjectsInRange_withObjectsFrom_range),
3434
("test_replaceObjectAtIndex", test_replaceObjectAtIndex),
3535
("test_removeObjectsInArray", test_removeObjectsInArray),
3636
("test_sortedArrayUsingComparator", test_sortedArrayUsingComparator),
@@ -174,7 +174,7 @@ class TestNSArray : XCTestCase {
174174
NSNumber(value: 0 as Int), NSNumber(value: 1 as Int), NSNumber(value: 2 as Int), NSNumber(value: 3 as Int),
175175
NSNumber(value: 4 as Int), NSNumber(value: 5 as Int), NSNumber(value: 7 as Int)]
176176
let array = NSMutableArray(array: numbers)
177-
array.replaceObjects(in: NSRange(location: 0, length: 2), withObjectsFromArray: [NSNumber(value: 8 as Int), NSNumber(value: 9 as Int)])
177+
array.replaceObjects(in: NSRange(location: 0, length: 2), withObjectsFrom: [NSNumber(value: 8 as Int), NSNumber(value: 9 as Int)])
178178
XCTAssertTrue((array[0] as! NSNumber).intValue == 8)
179179
XCTAssertTrue((array[1] as! NSNumber).intValue == 9)
180180
XCTAssertTrue((array[2] as! NSNumber).intValue == 2)
@@ -278,7 +278,7 @@ class TestNSArray : XCTestCase {
278278
return .orderedDescending
279279
}
280280

281-
func test_replaceObjectsInRange_withObjectsFromArray() {
281+
func test_replaceObjectsInRange_withObjectsFrom() {
282282
let array1 = NSMutableArray(array:[
283283
"foo1",
284284
"bar1",
@@ -289,15 +289,15 @@ class TestNSArray : XCTestCase {
289289
"bar2",
290290
"baz2"]
291291

292-
array1.replaceObjects(in: NSMakeRange(0, 2), withObjectsFromArray: array2)
292+
array1.replaceObjects(in: NSMakeRange(0, 2), withObjectsFrom: array2)
293293

294294
XCTAssertEqual(array1[0] as? String, "foo2", "Expected foo2 but was \(array1[0])")
295295
XCTAssertEqual(array1[1] as? String, "bar2", "Expected bar2 but was \(array1[1])")
296296
XCTAssertEqual(array1[2] as? String, "baz2", "Expected baz2 but was \(array1[2])")
297297
XCTAssertEqual(array1[3] as? String, "baz1", "Expected baz1 but was \(array1[3])")
298298
}
299299

300-
func test_replaceObjectsInRange_withObjectsFromArray_range() {
300+
func test_replaceObjectsInRange_withObjectsFrom_range() {
301301
let array1 = NSMutableArray(array:[
302302
"foo1",
303303
"bar1",
@@ -398,7 +398,7 @@ class TestNSArray : XCTestCase {
398398
let r = right as! String
399399
return l.localizedCaseInsensitiveCompare(r)
400400
}
401-
mutableStringsInput1.sort(comparator)
401+
mutableStringsInput1.sort(comparator: comparator)
402402
mutableStringsInput2.sort(options: [], usingComparator: comparator)
403403
XCTAssertTrue(mutableStringsInput1.isEqual(to: Array(mutableStringsInput2)))
404404
}

0 commit comments

Comments
 (0)