Skip to content

Commit bfc661d

Browse files
committed
Update method naming for usage of options
1 parent eca9791 commit bfc661d

File tree

9 files changed

+50
-50
lines changed

9 files changed

+50
-50
lines changed

Foundation/Dictionary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension Dictionary : _ObjectTypeBridgeable {
4747
var failedConversion = false
4848

4949
if type(of: source) == NSDictionary.self || type(of: source) == NSMutableDictionary.self {
50-
source.enumerateKeysAndObjects([]) { key, value, stop in
50+
source.enumerateKeysAndObjects(options: []) { key, value, stop in
5151
guard let key = key as? Key, let value = value as? Value else {
5252
failedConversion = true
5353
stop.pointee = true

Foundation/NSArray.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,13 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
386386
}
387387

388388
open func sortedArray(_ comparator: (Any, Any, UnsafeMutableRawPointer?) -> Int, context: UnsafeMutableRawPointer?) -> [Any] {
389-
return sortedArray([]) { lhs, rhs in
389+
return sortedArray(options: []) { lhs, rhs in
390390
return ComparisonResult(rawValue: comparator(lhs, rhs, context))!
391391
}
392392
}
393393

394394
open func sortedArray(_ comparator: (Any, Any, UnsafeMutableRawPointer?) -> Int, context: UnsafeMutableRawPointer?, hint: Data?) -> [Any] {
395-
return sortedArray([]) { lhs, rhs in
395+
return sortedArray(options: []) { lhs, rhs in
396396
return ComparisonResult(rawValue: comparator(lhs, rhs, context))!
397397
}
398398
}
@@ -426,13 +426,13 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
426426
return object(at: idx)
427427
}
428428

429-
public func enumerateObjects(_ block: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
430-
self.enumerateObjects([], using: block)
429+
open func enumerateObjects(_ block: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
430+
self.enumerateObjects(options: [], using: block)
431431
}
432-
public func enumerateObjects(_ opts: NSEnumerationOptions = [], using block: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
432+
open func enumerateObjects(options opts: NSEnumerationOptions = [], using block: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
433433
self.enumerateObjects(at: IndexSet(integersIn: 0..<count), options: opts, using: block)
434434
}
435-
public func enumerateObjects(at s: IndexSet, options opts: NSEnumerationOptions = [], using block: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
435+
open func enumerateObjects(at s: IndexSet, options opts: NSEnumerationOptions = [], using block: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
436436
guard !opts.contains(.concurrent) else {
437437
NSUnimplemented()
438438
}
@@ -459,9 +459,9 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
459459
}
460460

461461
open func indexesOfObjects(passingTest predicate: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> IndexSet {
462-
return indexesOfObjects([], passingTest: predicate)
462+
return indexesOfObjects(options: [], passingTest: predicate)
463463
}
464-
open func indexesOfObjects(_ opts: NSEnumerationOptions = [], passingTest predicate: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> IndexSet {
464+
open func indexesOfObjects(options opts: NSEnumerationOptions = [], passingTest predicate: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> IndexSet {
465465
return indexesOfObjects(at: IndexSet(integersIn: 0..<count), options: opts, passingTest: predicate)
466466
}
467467
open func indexesOfObjects(at s: IndexSet, options opts: NSEnumerationOptions = [], passingTest predicate: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> IndexSet {
@@ -495,7 +495,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
495495
return sortedArrayFromRange(NSMakeRange(0, count), options: [], usingComparator: cmptr)
496496
}
497497

498-
open func sortedArray(_ opts: SortOptions = [], usingComparator cmptr: (Any, Any) -> ComparisonResult) -> [Any] {
498+
open func sortedArray(options opts: SortOptions = [], usingComparator cmptr: (Any, Any) -> ComparisonResult) -> [Any] {
499499
return sortedArrayFromRange(NSMakeRange(0, count), options: opts, usingComparator: cmptr)
500500
}
501501

@@ -834,11 +834,11 @@ open class NSMutableArray : NSArray {
834834
}
835835

836836
open func sortUsingComparator(_ cmptr: Comparator) {
837-
self.sortWithOptions([], usingComparator: cmptr)
837+
self.sortWithOptions(options: [], usingComparator: cmptr)
838838
}
839839

840-
open func sortWithOptions(_ opts: SortOptions, usingComparator cmptr: Comparator) {
841-
self.setArray(self.sortedArray(opts, usingComparator: cmptr))
840+
open func sortWithOptions(options opts: SortOptions, usingComparator cmptr: Comparator) {
841+
self.setArray(self.sortedArray(options: opts, usingComparator: cmptr))
842842
}
843843

844844
public convenience init?(contentsOfFile path: String) { NSUnimplemented() }

Foundation/NSCFDictionary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ internal func _CFSwiftDictionaryGetValuesAndKeys(_ dictionary: AnyObject, valueb
177177
idx += 1
178178
}
179179
} else {
180-
dict.enumerateKeysAndObjects([]) { k, v, _ in
180+
dict.enumerateKeysAndObjects(options: []) { k, v, _ in
181181
let key = _SwiftValue.store(k)
182182
let value = _SwiftValue.store(v)
183183
valuebuf?[idx] = Unmanaged<AnyObject>.passUnretained(value)
@@ -189,7 +189,7 @@ internal func _CFSwiftDictionaryGetValuesAndKeys(_ dictionary: AnyObject, valueb
189189
}
190190

191191
internal func _CFSwiftDictionaryApplyFunction(_ dictionary: AnyObject, applier: @convention(c) (AnyObject, AnyObject, UnsafeMutableRawPointer) -> Void, context: UnsafeMutableRawPointer) {
192-
(dictionary as! NSDictionary).enumerateKeysAndObjects([]) { key, value, _ in
192+
(dictionary as! NSDictionary).enumerateKeysAndObjects(options: []) { key, value, _ in
193193
applier(_SwiftValue.store(key), _SwiftValue.store(value), context)
194194
}
195195
}

Foundation/NSDictionary.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
243243

244244
open func allKeys(for anObject: Any) -> [Any] {
245245
var matching = Array<Any>()
246-
enumerateKeysAndObjects([]) { key, value, _ in
246+
enumerateKeysAndObjects(options: []) { key, value, _ in
247247
if let val = value as? AnyHashable,
248248
let obj = anObject as? AnyHashable {
249249
if val == obj {
@@ -422,11 +422,11 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
422422
open func write(toFile path: String, atomically useAuxiliaryFile: Bool) -> Bool { NSUnimplemented() }
423423
open func write(to url: URL, atomically: Bool) -> Bool { NSUnimplemented() } // the atomically flag is ignored if url of a type that cannot be written atomically.
424424

425-
public func enumerateKeysAndObjects(_ block: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Void) {
426-
enumerateKeysAndObjects([], using: block)
425+
open func enumerateKeysAndObjects(_ block: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
426+
enumerateKeysAndObjects(options: [], using: block)
427427
}
428428

429-
public func enumerateKeysAndObjects(_ opts: NSEnumerationOptions = [], using block: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
429+
open func enumerateKeysAndObjects(options opts: NSEnumerationOptions = [], using block: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
430430
let count = self.count
431431
var keys = [Any]()
432432
var objects = [Any]()
@@ -444,25 +444,25 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
444444
}
445445

446446
open func keysSortedByValue(comparator cmptr: (Any, Any) -> ComparisonResult) -> [Any] {
447-
return keysSortedByValue([], usingComparator: cmptr)
447+
return keysSortedByValue(options: [], usingComparator: cmptr)
448448
}
449449

450-
open func keysSortedByValue(_ opts: SortOptions = [], usingComparator cmptr: (Any, Any) -> ComparisonResult) -> [Any] {
450+
open func keysSortedByValue(options opts: SortOptions = [], usingComparator cmptr: (Any, Any) -> ComparisonResult) -> [Any] {
451451
let sorted = allKeys.sorted { lhs, rhs in
452452
return cmptr(lhs, rhs) == .orderedSame
453453
}
454454
return sorted
455455
}
456456

457-
open func keysOfEntries(passingTest predicate: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<NSObject> {
458-
return keysOfEntries([], passingTest: predicate)
457+
open func keysOfEntries(passingTest predicate: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<AnyHashable> {
458+
return keysOfEntries(options: [], passingTest: predicate)
459459
}
460460

461-
open func keysOfEntries(_ opts: NSEnumerationOptions = [], passingTest predicate: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<NSObject> {
462-
var matching = Set<NSObject>()
463-
enumerateKeysAndObjects(opts) { key, value, stop in
461+
open func keysOfEntries(options opts: NSEnumerationOptions = [], passingTest predicate: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<AnyHashable> {
462+
var matching = Set<AnyHashable>()
463+
enumerateKeysAndObjects(options: opts) { key, value, stop in
464464
if predicate(key, value, stop) {
465-
matching.insert(key as! NSObject)
465+
matching.insert(key as! AnyHashable)
466466
}
467467
}
468468
return matching

Foundation/NSError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
5959
if let info = aDecoder.decodeObject(of: [NSSet.self, NSDictionary.self, NSArray.self, NSString.self, NSNumber.self, NSData.self, NSURL.self], forKey: "NSUserInfo") as? NSDictionary {
6060
var filteredUserInfo = [String : Any]()
6161
// user info must be filtered so that the keys are all strings
62-
info.enumerateKeysAndObjects([]) {
62+
info.enumerateKeysAndObjects(options: []) {
6363
if let key = $0.0 as? NSString {
6464
filteredUserInfo[key._swiftObject] = $0.1
6565
}
@@ -74,7 +74,7 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
7474
if let info = aDecoder.decodeObject() as? NSDictionary {
7575
var filteredUserInfo = [String : Any]()
7676
// user info must be filtered so that the keys are all strings
77-
info.enumerateKeysAndObjects([]) {
77+
info.enumerateKeysAndObjects(options: []) {
7878
if let key = $0.0 as? NSString {
7979
filteredUserInfo[key._swiftObject] = $0.1
8080
}

Foundation/NSLocale.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ extension NSLocale {
139139
open class func components(fromLocaleIdentifier string: String) -> [String : String] {
140140
var comps = Dictionary<String, String>()
141141
let values = CFLocaleCreateComponentsFromLocaleIdentifier(kCFAllocatorSystemDefault, string._cfObject)._nsObject
142-
values.enumerateKeysAndObjects([]) { (k, v, stop) in
142+
values.enumerateKeysAndObjects(options: []) { (k, v, stop) in
143143
let key = (k as! NSString)._swiftObject
144144
let value = (v as! NSString)._swiftObject
145145
comps[key] = value

Foundation/NSSet.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ extension NSSet {
176176

177177
extension NSSet {
178178

179-
public var allObjects: [Any] {
179+
open var allObjects: [Any] {
180180
if type(of: self) === NSSet.self || type(of: self) === NSMutableSet.self {
181181
return _storage.map { _SwiftValue.fetch($0) }
182182
} else {
@@ -189,15 +189,15 @@ extension NSSet {
189189
}
190190
}
191191

192-
public func anyObject() -> Any? {
192+
open func anyObject() -> Any? {
193193
return objectEnumerator().nextObject()
194194
}
195195

196-
public func contains(_ anObject: Any) -> Bool {
196+
open func contains(_ anObject: Any) -> Bool {
197197
return member(anObject) != nil
198198
}
199199

200-
public func intersects(_ otherSet: Set<AnyHashable>) -> Bool {
200+
open func intersects(_ otherSet: Set<AnyHashable>) -> Bool {
201201
if count < otherSet.count {
202202
for item in self {
203203
if otherSet.contains(item as! AnyHashable) {
@@ -210,11 +210,11 @@ extension NSSet {
210210
}
211211
}
212212

213-
public func isEqual(to otherSet: Set<AnyHashable>) -> Bool {
213+
open func isEqual(to otherSet: Set<AnyHashable>) -> Bool {
214214
return count == otherSet.count && isSubset(of: otherSet)
215215
}
216216

217-
public func isSubset(of otherSet: Set<AnyHashable>) -> Bool {
217+
open func isSubset(of otherSet: Set<AnyHashable>) -> Bool {
218218
// `true` if we don't contain any object that `otherSet` doesn't contain.
219219
for item in self {
220220
if !otherSet.contains(item as! AnyHashable) {
@@ -224,11 +224,11 @@ extension NSSet {
224224
return true
225225
}
226226

227-
public func adding(_ anObject: Any) -> Set<AnyHashable> {
227+
open func adding(_ anObject: Any) -> Set<AnyHashable> {
228228
return self.addingObjects(from: [anObject])
229229
}
230230

231-
public func addingObjects(from other: Set<AnyHashable>) -> Set<AnyHashable> {
231+
open func addingObjects(from other: Set<AnyHashable>) -> Set<AnyHashable> {
232232
var result = Set<AnyHashable>(minimumCapacity: Swift.max(count, other.count))
233233
if type(of: self) === NSSet.self || type(of: self) === NSMutableSet.self {
234234
result.formUnion(_storage.map { _SwiftValue.fetch($0) as! AnyHashable })
@@ -240,7 +240,7 @@ extension NSSet {
240240
return result.union(other)
241241
}
242242

243-
public func addingObjects(from other: [Any]) -> Set<AnyHashable> {
243+
open func addingObjects(from other: [Any]) -> Set<AnyHashable> {
244244
var result = Set<AnyHashable>(minimumCapacity: count)
245245
if type(of: self) === NSSet.self || type(of: self) === NSMutableSet.self {
246246
result.formUnion(_storage.map { _SwiftValue.fetch($0) as! AnyHashable })
@@ -255,11 +255,11 @@ extension NSSet {
255255
return result
256256
}
257257

258-
public func enumerateObjects(_ block: (Any, UnsafeMutablePointer<ObjCBool>) -> Void) {
259-
enumerateObjects([], using: block)
258+
open func enumerateObjects(_ block: (Any, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
259+
enumerateObjects(options: [], using: block)
260260
}
261261

262-
public func enumerateObjects(_ opts: NSEnumerationOptions = [], using block: (Any, UnsafeMutablePointer<ObjCBool>) -> Void) {
262+
open func enumerateObjects(options opts: NSEnumerationOptions = [], using block: (Any, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
263263
var stop : ObjCBool = false
264264
for obj in self {
265265
withUnsafeMutablePointer(to: &stop) { stop in
@@ -271,13 +271,13 @@ extension NSSet {
271271
}
272272
}
273273

274-
public func objects(passingTest predicate: (Any, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<AnyHashable> {
275-
return objects([], passingTest: predicate)
274+
open func objects(passingTest predicate: (Any, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<AnyHashable> {
275+
return objects(options: [], passingTest: predicate)
276276
}
277277

278-
public func objects(_ opts: NSEnumerationOptions = [], passingTest predicate: (Any, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<AnyHashable> {
278+
open func objects(options opts: NSEnumerationOptions = [], passingTest predicate: (Any, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<AnyHashable> {
279279
var result = Set<AnyHashable>()
280-
enumerateObjects(opts) { obj, stopp in
280+
enumerateObjects(options: opts) { obj, stopp in
281281
if predicate(obj, stopp) {
282282
result.insert(obj as! AnyHashable)
283283
}

Foundation/Set.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension Set : _ObjectTypeBridgeable {
3636
var failedConversion = false
3737

3838
if type(of: source) == NSSet.self || type(of: source) == NSMutableSet.self {
39-
source.enumerateObjects([]) { obj, stop in
39+
source.enumerateObjects(options: []) { obj, stop in
4040
if let o = obj as? Element {
4141
set.insert(o)
4242
} else {

TestFoundation/TestNSArray.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,12 @@ class TestNSArray : XCTestCase {
349349
return l.localizedCaseInsensitiveCompare(r)
350350
}
351351
let result1 = NSArray(array: input.sortedArray(comparator: comparator))
352-
let result2 = input.sortedArray([], usingComparator: comparator)
352+
let result2 = input.sortedArray(options: [], usingComparator: comparator)
353353

354354
XCTAssertTrue(result1.isEqual(to: result2))
355355

356356
// sort empty array
357-
let emptyArray = NSArray().sortedArray([]) { _,_ in .orderedSame }
357+
let emptyArray = NSArray().sortedArray(options: []) { _,_ in .orderedSame }
358358
XCTAssertTrue(emptyArray.isEmpty)
359359
}
360360

@@ -397,7 +397,7 @@ class TestNSArray : XCTestCase {
397397
return l.localizedCaseInsensitiveCompare(r)
398398
}
399399
mutableStringsInput1.sortUsingComparator(comparator)
400-
mutableStringsInput2.sortWithOptions([], usingComparator: comparator)
400+
mutableStringsInput2.sortWithOptions(options: [], usingComparator: comparator)
401401
XCTAssertTrue(mutableStringsInput1.isEqual(to: mutableStringsInput2.map { $0 }))
402402
}
403403

0 commit comments

Comments
 (0)