Skip to content

Commit d1b9837

Browse files
committed
Prefer for-in loops. Avoid usage of ++ operator.
1 parent 34ee75c commit d1b9837

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Foundation/NSArray.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
190190
}
191191

192192
public func indexOfObject(anObject: AnyObject) -> Int {
193-
for var idx = 0; idx < count; idx++ {
193+
for idx in 0..<count {
194194
let obj = objectAtIndex(idx) as! NSObject
195195
if anObject === obj || obj.isEqual(anObject) {
196196
return idx
@@ -200,7 +200,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
200200
}
201201

202202
public func indexOfObject(anObject: AnyObject, inRange range: NSRange) -> Int {
203-
for var idx = 0; idx < range.length; idx++ {
203+
for idx in 0..<range.length {
204204
let obj = objectAtIndex(idx + range.location) as! NSObject
205205
if anObject === obj || obj.isEqual(anObject) {
206206
return idx
@@ -210,7 +210,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
210210
}
211211

212212
public func indexOfObjectIdenticalTo(anObject: AnyObject) -> Int {
213-
for var idx = 0; idx < count; idx++ {
213+
for idx in 0..<count {
214214
let obj = objectAtIndex(idx) as! NSObject
215215
if anObject === obj {
216216
return idx
@@ -220,7 +220,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
220220
}
221221

222222
public func indexOfObjectIdenticalTo(anObject: AnyObject, inRange range: NSRange) -> Int {
223-
for var idx = 0; idx < range.length; idx++ {
223+
for idx in 0..<range.length {
224224
let obj = objectAtIndex(idx + range.location) as! NSObject
225225
if anObject === obj {
226226
return idx
@@ -234,7 +234,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
234234
return false
235235
}
236236

237-
for var idx = 0; idx < count; idx++ {
237+
for idx in 0..<count {
238238
let obj1 = objectAtIndex(idx) as! NSObject
239239
let obj2 = otherArray[idx] as! NSObject
240240
if obj1 === obj2 {
@@ -301,7 +301,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
301301
/*@NSCopying*/ public var sortedArrayHint: NSData {
302302
get {
303303
let buffer = UnsafeMutablePointer<Int32>.alloc(count)
304-
for var idx = 0; idx < count; idx++ {
304+
for idx in 0..<count {
305305
let item = objectAtIndex(idx) as! NSObject
306306
let hash = item.hash
307307
buffer.advancedBy(idx).memory = Int32(hash).littleEndian
@@ -512,7 +512,7 @@ public class NSMutableArray : NSArray {
512512

513513
public required convenience init(objects: UnsafePointer<AnyObject?>, count cnt: Int) {
514514
self.init(capacity: cnt)
515-
for var idx = 0; idx < cnt; idx++ {
515+
for idx in 0..<cnt {
516516
_storage.append(objects[idx]!)
517517
}
518518
}
@@ -608,10 +608,10 @@ public class NSMutableArray : NSArray {
608608
public func replaceObjectsInRange(range: NSRange, withObjectsFromArray otherArray: [AnyObject]) {
609609
if self.dynamicType === NSMutableArray.self {
610610
_storage.reserveCapacity(count - range.length + otherArray.count)
611-
for var idx = 0; idx < range.length; idx++ {
611+
for idx in 0..<range.length {
612612
_storage[idx + range.location] = otherArray[idx]
613613
}
614-
for var idx = range.length; idx < otherArray.count; idx++ {
614+
for idx in range.length..<otherArray.count {
615615
_storage.insert(otherArray[idx], atIndex: idx + range.location)
616616
}
617617
} else {

0 commit comments

Comments
 (0)