Skip to content

Add @noescape to Synchronous Enumeration, Predicate, and Comparator Blocks #4

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

Closed
wants to merge 3 commits into from
Closed
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
30 changes: 15 additions & 15 deletions Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,13 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
}
}

public func sortedArrayUsingFunction(comparator: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>) -> Int, context: UnsafeMutablePointer<Void>) -> [AnyObject] {
public func sortedArrayUsingFunction(@noescape comparator: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>) -> Int, context: UnsafeMutablePointer<Void>) -> [AnyObject] {
return sortedArrayWithOptions([]) { lhs, rhs in
return NSComparisonResult(rawValue: comparator(lhs, rhs, context))!
}
}

public func sortedArrayUsingFunction(comparator: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>) -> Int, context: UnsafeMutablePointer<Void>, hint: NSData?) -> [AnyObject] {
public func sortedArrayUsingFunction(@noescape comparator: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>) -> Int, context: UnsafeMutablePointer<Void>, hint: NSData?) -> [AnyObject] {
return sortedArrayWithOptions([]) { lhs, rhs in
return NSComparisonResult(rawValue: comparator(lhs, rhs, context))!
}
Expand Down Expand Up @@ -348,13 +348,13 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
}
}

public func enumerateObjectsUsingBlock(block: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateObjectsUsingBlock(@noescape block: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
self.enumerateObjectsWithOptions([], usingBlock: block)
}
public func enumerateObjectsWithOptions(opts: NSEnumerationOptions, usingBlock block: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateObjectsWithOptions(opts: NSEnumerationOptions, @noescape usingBlock block: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
self.enumerateObjectsAtIndexes(NSIndexSet(indexesInRange: NSMakeRange(0, count)), options: opts, usingBlock: block)
}
public func enumerateObjectsAtIndexes(s: NSIndexSet, options opts: NSEnumerationOptions, usingBlock block: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateObjectsAtIndexes(s: NSIndexSet, options opts: NSEnumerationOptions, @noescape usingBlock block: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
guard !opts.contains(.Concurrent) else {
NSUnimplemented()
}
Expand All @@ -364,13 +364,13 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
}
}

public func indexOfObjectPassingTest(predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
public func indexOfObjectPassingTest(@noescape predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
return indexOfObjectWithOptions([], passingTest: predicate)
}
public func indexOfObjectWithOptions(opts: NSEnumerationOptions, passingTest predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
public func indexOfObjectWithOptions(opts: NSEnumerationOptions, @noescape passingTest predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
return indexOfObjectAtIndexes(NSIndexSet(indexesInRange: NSMakeRange(0, count)), options: opts, passingTest: predicate)
}
public func indexOfObjectAtIndexes(s: NSIndexSet, options opts: NSEnumerationOptions, passingTest predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
public func indexOfObjectAtIndexes(s: NSIndexSet, options opts: NSEnumerationOptions, @noescape passingTest predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
var result = NSNotFound
enumerateObjectsAtIndexes(s, options: opts) { (obj, idx, stop) -> Void in
if predicate(obj, idx, stop) {
Expand All @@ -381,13 +381,13 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
return result
}

public func indexesOfObjectsPassingTest(predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
public func indexesOfObjectsPassingTest(@noescape predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
return indexesOfObjectsWithOptions([], passingTest: predicate)
}
public func indexesOfObjectsWithOptions(opts: NSEnumerationOptions, passingTest predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
public func indexesOfObjectsWithOptions(opts: NSEnumerationOptions, @noescape passingTest predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
return indexesOfObjectsAtIndexes(NSIndexSet(indexesInRange: NSMakeRange(0, count)), options: opts, passingTest: predicate)
}
public func indexesOfObjectsAtIndexes(s: NSIndexSet, options opts: NSEnumerationOptions, passingTest predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
public func indexesOfObjectsAtIndexes(s: NSIndexSet, options opts: NSEnumerationOptions, @noescape passingTest predicate: (AnyObject, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
let result = NSMutableIndexSet()
enumerateObjectsAtIndexes(s, options: opts) { (obj, idx, stop) in
if predicate(obj, idx, stop) {
Expand All @@ -397,7 +397,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
return result
}

internal func sortedArrayFromRange(range: NSRange, options: NSSortOptions, usingComparator cmptr: NSComparator) -> [AnyObject] {
internal func sortedArrayFromRange(range: NSRange, options: NSSortOptions, @noescape usingComparator cmptr: NSComparator) -> [AnyObject] {
let count = self.count
if range.length == 0 || count == 0 {
return []
Expand All @@ -408,15 +408,15 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
}
}

public func sortedArrayUsingComparator(cmptr: NSComparator) -> [AnyObject] {
public func sortedArrayUsingComparator(@noescape cmptr: NSComparator) -> [AnyObject] {
return sortedArrayFromRange(NSMakeRange(0, count), options: [], usingComparator: cmptr)
}

public func sortedArrayWithOptions(opts: NSSortOptions, usingComparator cmptr: NSComparator) -> [AnyObject] {
public func sortedArrayWithOptions(opts: NSSortOptions, @noescape usingComparator cmptr: NSComparator) -> [AnyObject] {
return sortedArrayFromRange(NSMakeRange(0, count), options: opts, usingComparator: cmptr)
}

public func indexOfObject(obj: AnyObject, inSortedRange r: NSRange, options opts: NSBinarySearchingOptions, usingComparator cmp: NSComparator) -> Int { NSUnimplemented() } // binary search
public func indexOfObject(obj: AnyObject, inSortedRange r: NSRange, options opts: NSBinarySearchingOptions, @noescape usingComparator cmp: NSComparator) -> Int { NSUnimplemented() } // binary search

public convenience init?(contentsOfFile path: String) { NSUnimplemented() }
public convenience init?(contentsOfURL url: NSURL) { NSUnimplemented() }
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSAttributedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class NSAttributedString : NSObject, NSCopying, NSMutableCopying, NSSecur
public init(string str: String, attributes attrs: [String : AnyObject]?) { NSUnimplemented() }
public init(attributedString attrStr: NSAttributedString) { NSUnimplemented() }

public func enumerateAttributesInRange(enumerationRange: NSRange, options opts: NSAttributedStringEnumerationOptions, usingBlock block: ([String : AnyObject], NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) { NSUnimplemented() }
public func enumerateAttribute(attrName: String, inRange enumerationRange: NSRange, options opts: NSAttributedStringEnumerationOptions, usingBlock block: (AnyObject?, NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) { NSUnimplemented() }
public func enumerateAttributesInRange(enumerationRange: NSRange, options opts: NSAttributedStringEnumerationOptions, @noescape usingBlock block: ([String : AnyObject], NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) { NSUnimplemented() }
public func enumerateAttribute(attrName: String, inRange enumerationRange: NSRange, options opts: NSAttributedStringEnumerationOptions, @noescape usingBlock block: (AnyObject?, NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) { NSUnimplemented() }
}

public struct NSAttributedStringEnumerationOptions : OptionSetType {
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
Result dates have an integer number of seconds (as if 0 was specified for the nanoseconds property of the NSDateComponents matching parameter), unless a value was set in the nanoseconds property, in which case the result date will have that number of nanoseconds (or as close as possible with floating point numbers).
The enumeration is stopped by setting *stop = YES in the block and return. It is not necessary to set *stop to NO to keep the enumeration going.
*/
public func enumerateDatesStartingAfterDate(start: NSDate, matchingComponents comps: NSDateComponents, options opts: NSCalendarOptions, usingBlock block: (NSDate?, Bool, UnsafeMutablePointer<ObjCBool>) -> Void) { NSUnimplemented() }
public func enumerateDatesStartingAfterDate(start: NSDate, matchingComponents comps: NSDateComponents, options opts: NSCalendarOptions, @noescape usingBlock block: (NSDate?, Bool, UnsafeMutablePointer<ObjCBool>) -> Void) { NSUnimplemented() }

/*
This method computes the next date which matches (or most closely matches) a given set of components.
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ extension NSData {
}
}

internal func enumerateByteRangesUsingBlockRethrows(block: (UnsafePointer<Void>, NSRange, UnsafeMutablePointer<Bool>) throws -> Void) throws {
internal func enumerateByteRangesUsingBlockRethrows(@noescape block: (UnsafePointer<Void>, NSRange, UnsafeMutablePointer<Bool>) throws -> Void) throws {
var err : ErrorType? = nil
self.enumerateByteRangesUsingBlock() { (buf, range, stop) -> Void in
do {
Expand All @@ -396,7 +396,7 @@ extension NSData {
}
}

public func enumerateByteRangesUsingBlock(block: (UnsafePointer<Void>, NSRange, UnsafeMutablePointer<Bool>) -> Void) {
public func enumerateByteRangesUsingBlock(@noescape block: (UnsafePointer<Void>, NSRange, UnsafeMutablePointer<Bool>) -> Void) {
var stop = false
withUnsafeMutablePointer(&stop) { stopPointer in
block(bytes, NSMakeRange(0, length), stopPointer)
Expand Down
12 changes: 6 additions & 6 deletions Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
public func writeToFile(path: String, atomically useAuxiliaryFile: Bool) -> Bool { NSUnimplemented() }
public func writeToURL(url: NSURL, atomically: Bool) -> Bool { NSUnimplemented() } // the atomically flag is ignored if url of a type that cannot be written atomically.

public func enumerateKeysAndObjectsUsingBlock(block: (NSObject, AnyObject, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateKeysAndObjectsUsingBlock(@noescape block: (NSObject, AnyObject, UnsafeMutablePointer<ObjCBool>) -> Void) {
enumerateKeysAndObjectsWithOptions([], usingBlock: block)
}

public func enumerateKeysAndObjectsWithOptions(opts: NSEnumerationOptions, usingBlock block: (NSObject, AnyObject, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateKeysAndObjectsWithOptions(opts: NSEnumerationOptions, @noescape usingBlock block: (NSObject, AnyObject, UnsafeMutablePointer<ObjCBool>) -> Void) {
let count = self.count
var keys = [AnyObject]()
var objects = [AnyObject]()
Expand All @@ -353,22 +353,22 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
}
}

public func keysSortedByValueUsingComparator(cmptr: NSComparator) -> [AnyObject] {
public func keysSortedByValueUsingComparator(@noescape cmptr: NSComparator) -> [AnyObject] {
return keysSortedByValueWithOptions([], usingComparator: cmptr)
}

public func keysSortedByValueWithOptions(opts: NSSortOptions, usingComparator cmptr: NSComparator) -> [AnyObject] {
public func keysSortedByValueWithOptions(opts: NSSortOptions, @noescape usingComparator cmptr: NSComparator) -> [AnyObject] {
let sorted = allKeys.sort { lhs, rhs in
return cmptr(lhs, rhs) == .OrderedSame
}
return sorted
}

public func keysOfEntriesPassingTest(predicate: (AnyObject, AnyObject, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<NSObject> {
public func keysOfEntriesPassingTest(@noescape predicate: (AnyObject, AnyObject, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<NSObject> {
return keysOfEntriesWithOptions([], passingTest: predicate)
}

public func keysOfEntriesWithOptions(opts: NSEnumerationOptions, passingTest predicate: (AnyObject, AnyObject, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<NSObject> {
public func keysOfEntriesWithOptions(opts: NSEnumerationOptions, @noescape passingTest predicate: (AnyObject, AnyObject, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Set<NSObject> {
var matching = Set<NSObject>()
enumerateKeysAndObjectsWithOptions(opts) { key, value, stop in
if predicate(key, value, stop) {
Expand Down
26 changes: 13 additions & 13 deletions Foundation/NSIndexSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding
return false
}

internal func _enumerateWithOptions<P, R>(opts : NSEnumerationOptions, range: NSRange, paramType: P.Type, returnType: R.Type, block: (P, UnsafeMutablePointer<ObjCBool>) -> R) -> Int? {
internal func _enumerateWithOptions<P, R>(opts : NSEnumerationOptions, range: NSRange, paramType: P.Type, returnType: R.Type, @noescape block: (P, UnsafeMutablePointer<ObjCBool>) -> R) -> Int? {
guard !opts.contains(.Concurrent) else {
NSUnimplemented()
}
Expand Down Expand Up @@ -378,33 +378,33 @@ public class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding
return result
}

public func enumerateIndexesUsingBlock(block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateIndexesUsingBlock(@noescape block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
enumerateIndexesWithOptions([], usingBlock: block)
}
public func enumerateIndexesWithOptions(opts: NSEnumerationOptions, usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateIndexesWithOptions(opts: NSEnumerationOptions, @noescape usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
_enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: Int.self, returnType: Void.self, block: block)
}
public func enumerateIndexesInRange(range: NSRange, options opts: NSEnumerationOptions, usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateIndexesInRange(range: NSRange, options opts: NSEnumerationOptions, @noescape usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
_enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self, block: block)
}

public func indexPassingTest(predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
public func indexPassingTest(@noescape predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
return indexWithOptions([], passingTest: predicate)
}
public func indexWithOptions(opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
public func indexWithOptions(opts: NSEnumerationOptions, @noescape passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
return _enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: Int.self, returnType: Bool.self, block: predicate) ?? NSNotFound
}
public func indexInRange(range: NSRange, options opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
public func indexInRange(range: NSRange, options opts: NSEnumerationOptions, @noescape passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
return _enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Bool.self, block: predicate) ?? NSNotFound
}

public func indexesPassingTest(predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
public func indexesPassingTest(@noescape predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
return indexesInRange(NSMakeRange(0, Int.max), options: [], passingTest: predicate)
}
public func indexesWithOptions(opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
public func indexesWithOptions(opts: NSEnumerationOptions, @noescape passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
return indexesInRange(NSMakeRange(0, Int.max), options: opts, passingTest: predicate)
}
public func indexesInRange(range: NSRange, options opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
public func indexesInRange(range: NSRange, options opts: NSEnumerationOptions, @noescape passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
let result = NSMutableIndexSet()
_enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self) { idx, stop in
if predicate(idx, stop) {
Expand All @@ -419,13 +419,13 @@ public class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding

If the specified range for enumeration intersects a range of contiguous indexes in the receiver, then the block will be invoked with the intersection of those two ranges.
*/
public func enumerateRangesUsingBlock(block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateRangesUsingBlock(@noescape block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
enumerateRangesWithOptions([], usingBlock: block)
}
public func enumerateRangesWithOptions(opts: NSEnumerationOptions, usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateRangesWithOptions(opts: NSEnumerationOptions, @noescape usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
_enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: NSRange.self, returnType: Void.self, block: block)
}
public func enumerateRangesInRange(range: NSRange, options opts: NSEnumerationOptions, usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateRangesInRange(range: NSRange, options opts: NSEnumerationOptions, @noescape usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
_enumerateWithOptions(opts, range: range, paramType: NSRange.self, returnType: Void.self, block: block)
}

Expand Down
Loading