Skip to content

[noescape by default] Add explicit @escaping for escaping closure #492

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
Jul 29, 2016
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
4 changes: 2 additions & 2 deletions Foundation/NSJSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private struct JSONWriter {
let pretty: Bool
let writer: (String?) -> Void

init(pretty: Bool = false, writer: (String?) -> Void) {
init(pretty: Bool = false, writer: @escaping (String?) -> Void) {
self.pretty = pretty
self.writer = writer
}
Expand Down Expand Up @@ -521,7 +521,7 @@ private struct JSONReader {
return index
}

func takeMatching(_ match: (UInt8) -> Bool) -> ([Character], Index) -> ([Character], Index)? {
func takeMatching(_ match: @escaping (UInt8) -> Bool) -> ([Character], Index) -> ([Character], Index)? {
return { input, index in
guard let (byte, index) = self.source.takeASCII(index), match(byte) else {
return nil
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public class NotificationCenter: NSObject {
})
}

public func addObserverForName(_ name: Notification.Name?, object obj: AnyObject?, queue: OperationQueue?, usingBlock block: (Notification) -> Void) -> NSObjectProtocol {
public func addObserverForName(_ name: Notification.Name?, object obj: AnyObject?, queue: OperationQueue?, usingBlock block: @escaping (Notification) -> Void) -> NSObjectProtocol {
if queue != nil {
NSUnimplemented()
}
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public class BlockOperation: Operation {
internal var _block: () -> Void
internal var _executionBlocks = [ExecutionBlock]()

public init(block: () -> Void) {
public init(block: @escaping () -> Void) {
_block = block
}

Expand All @@ -187,7 +187,7 @@ public class BlockOperation: Operation {
executionBlocks.forEach { $0() }
}

public func addExecutionBlock(_ block: () -> Void) {
public func addExecutionBlock(_ block: @escaping () -> Void) {
lock.lock()
_executionBlocks.append(block)
lock.unlock()
Expand Down Expand Up @@ -437,7 +437,7 @@ public class OperationQueue: NSObject {
lock.unlock()
}

public func addOperationWithBlock(_ block: () -> Void) {
public func addOperationWithBlock(_ block: @escaping () -> Void) {
let op = BlockOperation(block: block)
op.qualityOfService = qualityOfService
addOperation(op)
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSPredicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Predicate : NSObject, NSSecureCoding, NSCopying {
super.init()
} // return predicates that always evaluate to true/false

public init(block: (AnyObject?, [String : AnyObject]?) -> Bool) {
public init(block: @escaping (AnyObject?, [String : AnyObject]?) -> Bool) {
kind = .block(block)
super.init()
}
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSRegularExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public struct NSMatchingFlags : OptionSet {
internal class _NSRegularExpressionMatcher {
var regex: RegularExpression
var block: (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
init(regex: RegularExpression, block: (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void) {
init(regex: RegularExpression, block: @escaping (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void) {
self.regex = regex
self.block = block
}
Expand Down Expand Up @@ -147,7 +147,7 @@ extension RegularExpression {
/* The fundamental matching method on NSRegularExpression is a block iterator. There are several additional convenience methods, for returning all matches at once, the number of matches, the first match, or the range of the first match. Each match is specified by an instance of NSTextCheckingResult (of type NSTextCheckingTypeRegularExpression) in which the overall match range is given by the range property (equivalent to range at:0) and any capture group ranges are given by range at: for indexes from 1 to numberOfCaptureGroups. {NSNotFound, 0} is used if a particular capture group does not participate in the match.
*/

public func enumerateMatches(in string: String, options: NSMatchingOptions, range: NSRange, using block: (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
public func enumerateMatches(in string: String, options: NSMatchingOptions, range: NSRange, using block: @escaping (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
let matcher = _NSRegularExpressionMatcher(regex: self, block: block)
withExtendedLifetime(matcher) { (m: _NSRegularExpressionMatcher) -> Void in
#if os(OSX) || os(iOS)
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSRunLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ extension RunLoop {
return true
}

public func perform(inModes modes: [RunLoopMode], block: () -> Void) {
public func perform(inModes modes: [RunLoopMode], block: @escaping () -> Void) {
CFRunLoopPerformBlock(getCFRunLoop(), (modes.map { $0.rawValue._nsObject })._cfObject, block)
}

public func perform(_ block: () -> Void) {
public func perform(_ block: @escaping () -> Void) {
perform(inModes: [.defaultRunLoopMode], block: block)
}
}
4 changes: 2 additions & 2 deletions Foundation/NSThread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class Thread: NSObject {
/// Alternative API for detached thread creation
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative to creation via selector
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
public class func detachNewThread(_ main: (Void) -> Void) {
public class func detachNewThread(_ main: @escaping (Void) -> Void) {
let t = Thread(main)
t.start()
}
Expand Down Expand Up @@ -142,7 +142,7 @@ public class Thread: NSObject {
_thread = thread
}

public init(_ main: (Void) -> Void) {
public init(_ main: @escaping (Void) -> Void) {
_main = main
let _ = withUnsafeMutablePointer(to: &_attr) { attr in
pthread_attr_init(attr)
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Timer: NSObject {
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative to creation via selector
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
/// - Warning: Capturing the timer or the owner of the timer inside of the block may cause retain cycles. Use with caution
public init(fire date: Date, interval: TimeInterval, repeats: Bool, block: (Timer) -> Swift.Void) {
public init(fire date: Date, interval: TimeInterval, repeats: Bool, block: @escaping (Timer) -> Swift.Void) {
super.init()
_fire = block
var context = CFRunLoopTimerContext()
Expand All @@ -56,7 +56,7 @@ public class Timer: NSObject {
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative to creation via selector
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
/// - Warning: Capturing the timer or the owner of the timer inside of the block may cause retain cycles. Use with caution
public class func scheduledTimer(withTimeInterval interval: TimeInterval, repeats: Bool, block: (Timer) -> Void) -> Timer {
public class func scheduledTimer(withTimeInterval interval: TimeInterval, repeats: Bool, block: @escaping (Timer) -> Void) -> Timer {
let timer = Timer(fire: Date(timeIntervalSinceNow: interval), interval: interval, repeats: repeats, block: block)
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer._timer!, kCFRunLoopDefaultMode)
return timer
Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSNotificationQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class TestNSNotificationQueue : XCTestCase {
waitForExpectations(timeout: 0.1)
}

private func executeInBackgroundThread(_ operation: () -> Void) {
private func executeInBackgroundThread(_ operation: @escaping () -> Void) {
let e = expectation(description: "Background Execution")
let bgThread = Thread() {
operation()
Expand Down