Skip to content

Commit df08be3

Browse files
committed
Merge pull request #22 from BryanHoke/patch-1
Prefer for-in loops. Avoid usage of ++ operator.
2 parents 37cef8a + d1b9837 commit df08be3

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
@@ -189,7 +189,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
189189
}
190190

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

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

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

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

236-
for var idx = 0; idx < count; idx++ {
236+
for idx in 0..<count {
237237
let obj1 = objectAtIndex(idx) as! NSObject
238238
let obj2 = otherArray[idx] as! NSObject
239239
if obj1 === obj2 {
@@ -300,7 +300,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
300300
/*@NSCopying*/ public var sortedArrayHint: NSData {
301301
get {
302302
let buffer = UnsafeMutablePointer<Int32>.alloc(count)
303-
for var idx = 0; idx < count; idx++ {
303+
for idx in 0..<count {
304304
let item = objectAtIndex(idx) as! NSObject
305305
let hash = item.hash
306306
buffer.advancedBy(idx).memory = Int32(hash).littleEndian
@@ -511,7 +511,7 @@ public class NSMutableArray : NSArray {
511511

512512
public required convenience init(objects: UnsafePointer<AnyObject?>, count cnt: Int) {
513513
self.init(capacity: cnt)
514-
for var idx = 0; idx < cnt; idx++ {
514+
for idx in 0..<cnt {
515515
_storage.append(objects[idx]!)
516516
}
517517
}
@@ -607,10 +607,10 @@ public class NSMutableArray : NSArray {
607607
public func replaceObjectsInRange(range: NSRange, withObjectsFromArray otherArray: [AnyObject]) {
608608
if self.dynamicType === NSMutableArray.self {
609609
_storage.reserveCapacity(count - range.length + otherArray.count)
610-
for var idx = 0; idx < range.length; idx++ {
610+
for idx in 0..<range.length {
611611
_storage[idx + range.location] = otherArray[idx]
612612
}
613-
for var idx = range.length; idx < otherArray.count; idx++ {
613+
for idx in range.length..<otherArray.count {
614614
_storage.insert(otherArray[idx], atIndex: idx + range.location)
615615
}
616616
} else {

0 commit comments

Comments
 (0)