Skip to content

Commit 5072fd7

Browse files
committed
[noescape by default] Add explicit @escaping for escaping closures
1 parent 3b9a917 commit 5072fd7

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

Foundation/NSJSONSerialization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private struct JSONWriter {
240240
let pretty: Bool
241241
let writer: (String?) -> Void
242242

243-
init(pretty: Bool = false, writer: (String?) -> Void) {
243+
init(pretty: Bool = false, writer: @escaping (String?) -> Void) {
244244
self.pretty = pretty
245245
self.writer = writer
246246
}
@@ -521,7 +521,7 @@ private struct JSONReader {
521521
return index
522522
}
523523

524-
func takeMatching(_ match: (UInt8) -> Bool) -> ([Character], Index) -> ([Character], Index)? {
524+
func takeMatching(_ match: @escaping (UInt8) -> Bool) -> ([Character], Index) -> ([Character], Index)? {
525525
return { input, index in
526526
guard let (byte, index) = self.source.takeASCII(index), match(byte) else {
527527
return nil

Foundation/NSNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public class NotificationCenter: NSObject {
208208
})
209209
}
210210

211-
public func addObserverForName(_ name: Notification.Name?, object obj: AnyObject?, queue: OperationQueue?, usingBlock block: (Notification) -> Void) -> NSObjectProtocol {
211+
public func addObserverForName(_ name: Notification.Name?, object obj: AnyObject?, queue: OperationQueue?, usingBlock block: @escaping (Notification) -> Void) -> NSObjectProtocol {
212212
if queue != nil {
213213
NSUnimplemented()
214214
}

Foundation/NSOperation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public class BlockOperation: Operation {
174174
internal var _block: () -> Void
175175
internal var _executionBlocks = [ExecutionBlock]()
176176

177-
public init(block: () -> Void) {
177+
public init(block: @escaping () -> Void) {
178178
_block = block
179179
}
180180

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

190-
public func addExecutionBlock(_ block: () -> Void) {
190+
public func addExecutionBlock(_ block: @escaping () -> Void) {
191191
lock.lock()
192192
_executionBlocks.append(block)
193193
lock.unlock()
@@ -437,7 +437,7 @@ public class OperationQueue: NSObject {
437437
lock.unlock()
438438
}
439439

440-
public func addOperationWithBlock(_ block: () -> Void) {
440+
public func addOperationWithBlock(_ block: @escaping () -> Void) {
441441
let op = BlockOperation(block: block)
442442
op.qualityOfService = qualityOfService
443443
addOperation(op)

Foundation/NSPredicate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class Predicate : NSObject, NSSecureCoding, NSCopying {
5151
super.init()
5252
} // return predicates that always evaluate to true/false
5353

54-
public init(block: (AnyObject?, [String : AnyObject]?) -> Bool) {
54+
public init(block: @escaping (AnyObject?, [String : AnyObject]?) -> Bool) {
5555
kind = .block(block)
5656
super.init()
5757
}

Foundation/NSRegularExpression.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public struct NSMatchingFlags : OptionSet {
114114
internal class _NSRegularExpressionMatcher {
115115
var regex: RegularExpression
116116
var block: (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
117-
init(regex: RegularExpression, block: (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void) {
117+
init(regex: RegularExpression, block: @escaping (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void) {
118118
self.regex = regex
119119
self.block = block
120120
}
@@ -147,7 +147,7 @@ extension RegularExpression {
147147
/* 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.
148148
*/
149149

150-
public func enumerateMatches(in string: String, options: NSMatchingOptions, range: NSRange, using block: (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
150+
public func enumerateMatches(in string: String, options: NSMatchingOptions, range: NSRange, using block: @escaping (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
151151
let matcher = _NSRegularExpressionMatcher(regex: self, block: block)
152152
withExtendedLifetime(matcher) { (m: _NSRegularExpressionMatcher) -> Void in
153153
#if os(OSX) || os(iOS)

Foundation/NSRunLoop.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ extension RunLoop {
150150
return true
151151
}
152152

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

157-
public func perform(_ block: () -> Void) {
157+
public func perform(_ block: @escaping () -> Void) {
158158
perform(inModes: [.defaultRunLoopMode], block: block)
159159
}
160160
}

Foundation/NSThread.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class Thread: NSObject {
6868
/// Alternative API for detached thread creation
6969
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative to creation via selector
7070
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
71-
public class func detachNewThread(_ main: (Void) -> Void) {
71+
public class func detachNewThread(_ main: @escaping (Void) -> Void) {
7272
let t = Thread(main)
7373
t.start()
7474
}
@@ -142,7 +142,7 @@ public class Thread: NSObject {
142142
_thread = thread
143143
}
144144

145-
public init(_ main: (Void) -> Void) {
145+
public init(_ main: @escaping (Void) -> Void) {
146146
_main = main
147147
let _ = withUnsafeMutablePointer(to: &_attr) { attr in
148148
pthread_attr_init(attr)

Foundation/NSTimer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Timer: NSObject {
3434
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative to creation via selector
3535
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
3636
/// - Warning: Capturing the timer or the owner of the timer inside of the block may cause retain cycles. Use with caution
37-
public init(fire date: Date, interval: TimeInterval, repeats: Bool, block: (Timer) -> Swift.Void) {
37+
public init(fire date: Date, interval: TimeInterval, repeats: Bool, block: @escaping (Timer) -> Swift.Void) {
3838
super.init()
3939
_fire = block
4040
var context = CFRunLoopTimerContext()
@@ -56,7 +56,7 @@ public class Timer: NSObject {
5656
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative to creation via selector
5757
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
5858
/// - Warning: Capturing the timer or the owner of the timer inside of the block may cause retain cycles. Use with caution
59-
public class func scheduledTimer(withTimeInterval interval: TimeInterval, repeats: Bool, block: (Timer) -> Void) -> Timer {
59+
public class func scheduledTimer(withTimeInterval interval: TimeInterval, repeats: Bool, block: @escaping (Timer) -> Void) -> Timer {
6060
let timer = Timer(fire: Date(timeIntervalSinceNow: interval), interval: interval, repeats: repeats, block: block)
6161
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer._timer!, kCFRunLoopDefaultMode)
6262
return timer

0 commit comments

Comments
 (0)