Skip to content

A small step towards removing C-style loops #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Foundation/NSCFArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal func _CFSwiftArrayGetValueAtIndex(array: AnyObject, _ index: CFIndex) -
}

internal func _CFSwiftArrayGetValues(array: AnyObject, _ range: CFRange, _ values: UnsafeMutablePointer<Unmanaged<AnyObject>?>) {
for var idx = 0; idx < range.length; idx++ {
for idx in 0..<range.length {
let obj = (array as! NSArray).objectAtIndex(idx + range.location)
values[idx] = Unmanaged.passUnretained(obj)
}
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSCFDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal final class _NSCFDictionary : NSMutableDictionary {
let keys = UnsafeMutablePointer<UnsafePointer<Void>>.alloc(count)
CFDictionaryGetKeysAndValues(cf, keys, nil)

for var idx = 0; idx < count; idx++ {
for idx in 0..<count {
let key = unsafeBitCast(keys.advancedBy(idx).memory, NSObject.self)
keyArray.append(key)
}
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSCFString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal func _CFSwiftStringGetBytes(str: AnyObject, range: CFRange, buffer: Uns
let s = (str as! NSString)._swiftObject.utf8
let start = s.startIndex
if buffer != nil {
for var idx = 0; idx < range.length; idx++ {
for idx in 0..<range.length {
let c = s[start.advancedBy(idx + range.location)]
buffer.advancedBy(idx).initialize(c)
}
Expand Down
10 changes: 5 additions & 5 deletions Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension Dictionary : _ObjectiveCBridgeable {

CFDictionaryGetKeysAndValues(cf, keys, values)

for var idx = 0; idx < cnt; idx++ {
for idx in 0..<cnt {
let key = unsafeBitCast(keys.advancedBy(idx).memory, AnyObject.self)
let value = unsafeBitCast(values.advancedBy(idx).memory, AnyObject.self)
if let k = key as? Key {
Expand Down Expand Up @@ -136,7 +136,7 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
}

public required init(objects: UnsafePointer<AnyObject>, forKeys keys: UnsafePointer<NSObject>, count cnt: Int) {
for var idx = 0; idx < cnt; idx++ {
for idx in 0..<cnt {
let key = keys[idx].copy()
let value = objects[idx]
_storage[key as! NSObject] = value
Expand Down Expand Up @@ -189,11 +189,11 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin

public convenience init(objects: [AnyObject], forKeys keys: [NSObject]) {
let keyBuffer = UnsafeMutablePointer<NSObject>.alloc(keys.count)
for var idx = 0; idx < keys.count; idx++ {
for idx in 0..<keys.count {
keyBuffer[idx] = keys[idx]
}
let valueBuffer = UnsafeMutablePointer<AnyObject>.alloc(objects.count)
for var idx = 0; idx < objects.count; idx++ {
for idx in 0..<objects.count {
valueBuffer[idx] = objects[idx]
}

Expand Down Expand Up @@ -357,7 +357,7 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
var objects = [AnyObject]()
getObjects(&objects, andKeys: &keys, count: count)
var stop = ObjCBool(false)
for var idx = 0; idx < count; idx++ {
for idx in 0..<count {
withUnsafeMutablePointer(&stop, { stop in
block(keys[idx] as! NSObject, objects[idx], stop)
})
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension Set : _ObjectiveCBridgeable {

CFSetGetValues(cf, objs)

for var idx = 0; idx < cnt; idx++ {
for idx in 0..<cnt {
let obj = unsafeBitCast(objs.advancedBy(idx), AnyObject.self)
if let o = obj as? Element {
set.insert(o)
Expand Down Expand Up @@ -176,7 +176,7 @@ extension NSSet {

public convenience init(array: [AnyObject]) {
let buffer = UnsafeMutablePointer<AnyObject?>.alloc(array.count)
for var idx = 0; idx < array.count; idx++ {
for idx in 0..<array.count {
buffer.advancedBy(idx).initialize(array[idx])
}
self.init(objects: buffer, count: array.count)
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public class NSString : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, N

extension NSString {
public func getCharacters(buffer: UnsafeMutablePointer<unichar>, range: NSRange) {
for var idx = 0; idx < range.length; idx++ {
for idx in 0..<range.length {
buffer[idx] = characterAtIndex(idx + range.location)
}
}
Expand Down Expand Up @@ -901,7 +901,7 @@ extension String {
if characters.count < prefixCharacters.count {
return false
}
for var idx = 0; idx < prefixCharacters.count; idx++ {
for idx in 0..<prefixCharacters.count {
if characters[start.advancedBy(idx)] != prefixCharacters[prefixStart.advancedBy(idx)] {
return false
}
Expand All @@ -918,7 +918,7 @@ extension String {
if characters.count < suffixCharacters.count {
return false
}
for var idx = 0; idx < suffixCharacters.count; idx++ {
for idx in 0..<suffixCharacters.count {
let charactersIdx = start.advancedBy(characters.count - idx - 1)
let suffixIdx = suffixStart.advancedBy(suffixCharacters.count - idx - 1)
if characters[charactersIdx] != suffixCharacters[suffixIdx] {
Expand Down