Skip to content

Commit 3abd700

Browse files
otaviolimaparkera
authored andcommitted
Remove explicit use of .some & .none when dealing with optionals (#1609)
1 parent c820eb7 commit 3abd700

File tree

7 files changed

+38
-39
lines changed

7 files changed

+38
-39
lines changed

Foundation/IndexSet.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
8282
case (nil, nil):
8383
startIndex = 0
8484
endIndex = 0
85-
case (nil, .some(let max)):
85+
case (nil, let max?):
8686
// Start is before our first range
8787
startIndex = 0
8888
endIndex = max + 1
89-
case (.some(let min), nil):
89+
case (let min?, nil):
9090
// End is after our last range
9191
startIndex = min
9292
endIndex = indexSet._rangeCount
93-
case (.some(let min), .some(let max)):
93+
case (let min?, let max?):
9494
startIndex = min
9595
endIndex = max + 1
9696
}

Foundation/JSONSerialization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ private struct JSONReader {
685685
func consumeASCII(_ ascii: UInt8) -> (Index) throws -> Index? {
686686
return { (input: Index) throws -> Index? in
687687
switch self.source.takeASCII(input) {
688-
case .none:
688+
case nil:
689689
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.propertyListReadCorrupt.rawValue, userInfo: [
690690
"NSDebugDescription" : "Unexpected end of file during JSON parse."
691691
])

Foundation/URLSession/BodySource.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ fileprivate extension _BodyFileSource {
167167
switch (done, data, errno) {
168168
case (true, _, errno) where errno != 0:
169169
self.availableChunk = .errorDetected(Int(errno))
170-
case (true, .some(let d), 0) where d.isEmpty:
170+
case (true, let d?, 0) where d.isEmpty:
171171
self.append(data: d, endOfFile: true)
172-
case (true, .some(let d), 0):
172+
case (true, let d?, 0):
173173
self.append(data: d, endOfFile: false)
174-
case (false, .some(let d), 0):
174+
case (false, let d?, 0):
175175
self.append(data: d, endOfFile: false)
176176
default:
177177
fatalError("Invalid arguments to read(3) callback.")
@@ -202,8 +202,8 @@ fileprivate extension _BodyFileSource {
202202
case .empty: return 0
203203
case .errorDetected: return 0
204204
case .data(let d): return d.count
205-
case .done(.some(let d)): return d.count
206-
case .done(.none): return 0
205+
case .done(let d?): return d.count
206+
case .done(nil): return 0
207207
}
208208
}
209209
}
@@ -228,7 +228,7 @@ extension _BodyFileSource : _BodySource {
228228
} else {
229229
return .data(head)
230230
}
231-
case .done(.some(let data)):
231+
case .done(let data?):
232232
let l = min(length, data.count)
233233
let (head, tail) = splitData(dispatchData: data, atPosition: l)
234234
availableChunk = tail.isEmpty ? .done(nil) : .done(tail)
@@ -237,7 +237,7 @@ extension _BodyFileSource : _BodySource {
237237
} else {
238238
return .data(head)
239239
}
240-
case .done(.none):
240+
case .done(nil):
241241
return .done
242242
}
243243
}

Foundation/URLSession/URLSession.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,10 @@ internal extension URLSession {
535535
case .dataCompletionHandler(let c): return .dataCompletionHandler(c)
536536
case .downloadCompletionHandler(let c): return .downloadCompletionHandler(c)
537537
case .callDelegate:
538-
switch delegate {
539-
case .none: return .noDelegate
540-
case .some(let d as URLSessionTaskDelegate): return .taskDelegate(d)
541-
case .some: return .noDelegate
538+
guard let d = delegate as? URLSessionTaskDelegate else {
539+
return .noDelegate
542540
}
541+
return .taskDelegate(d)
543542
}
544543
}
545544
}

Foundation/URLSession/http/HTTPURLProtocol.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ internal class _HTTPURLProtocol: _NativeProtocol {
8585
easyHandle.set(preferredReceiveBufferSize: Int.max)
8686
do {
8787
switch (task?.body, try task?.body.getBodyLength()) {
88-
case (.none, _):
88+
case (nil, _):
8989
set(requestBodyLength: .noBody)
90-
case (_, .some(let length)):
90+
case (_, let length?):
9191
set(requestBodyLength: .length(length))
9292
task!.countOfBytesExpectedToSend = Int64(length)
93-
case (_, .none):
93+
case (_, nil):
9494
set(requestBodyLength: .unknown)
9595
}
9696
} catch let e {
@@ -289,7 +289,7 @@ fileprivate extension _HTTPURLProtocol {
289289
/// Any header values that should be removed from the ones set by libcurl
290290
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_HTTPHEADER.html
291291
var curlHeadersToRemove: [String] {
292-
if case .none = task?.body {
292+
if task?.body == nil {
293293
return []
294294
} else {
295295
return ["Expect"]

Foundation/URLSession/libcurl/EasyHandle.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,12 @@ fileprivate extension _EasyHandle {
503503
let d: Int = {
504504
let buffer = Data(bytes: data, count: size*nmemb)
505505
switch delegate?.didReceive(data: buffer) {
506-
case .some(.proceed): return size * nmemb
507-
case .some(.abort): return 0
508-
case .some(.pause):
506+
case .proceed?: return size * nmemb
507+
case .abort?: return 0
508+
case .pause?:
509509
pauseState.insert(.receivePaused)
510510
return Int(CFURLSessionWriteFuncPause)
511-
case .none:
511+
case nil:
512512
/* the delegate disappeared */
513513
return 0
514514
}
@@ -523,12 +523,12 @@ fileprivate extension _EasyHandle {
523523
let buffer = Data(bytes: data, count: size*nmemb)
524524
let d: Int = {
525525
switch delegate?.didReceive(headerData: buffer, contentLength: Int64(contentLength)) {
526-
case .some(.proceed): return size * nmemb
527-
case .some(.abort): return 0
528-
case .some(.pause):
526+
case .proceed?: return size * nmemb
527+
case .abort?: return 0
528+
case .pause?:
529529
pauseState.insert(.receivePaused)
530530
return Int(CFURLSessionWriteFuncPause)
531-
case .none:
531+
case nil:
532532
/* the delegate disappeared */
533533
return 0
534534
}
@@ -563,14 +563,14 @@ fileprivate extension _EasyHandle {
563563
let d: Int = {
564564
let buffer = UnsafeMutableBufferPointer(start: data, count: size * nmemb)
565565
switch delegate?.fill(writeBuffer: buffer) {
566-
case .some(.pause):
566+
case .pause?:
567567
pauseState.insert(.sendPaused)
568568
return Int(CFURLSessionReadFuncPause)
569-
case .some(.abort):
569+
case .abort?:
570570
return Int(CFURLSessionReadFuncAbort)
571-
case .some(.bytes(let length)):
572-
return length
573-
case .none:
571+
case .bytes(let length)?:
572+
return length
573+
case nil:
574574
/* the delegate disappeared */
575575
return Int(CFURLSessionReadFuncAbort)
576576
}

TestFoundation/TestJSONEncoder.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,11 +590,11 @@ func expectEqualPaths(_ lhs: [CodingKey?], _ rhs: [CodingKey?], _ prefix: String
590590

591591
for (k1, k2) in zip(lhs, rhs) {
592592
switch (k1, k2) {
593-
case (.none, .none): continue
594-
case (.some(let _k1), .none):
593+
case (nil, nil): continue
594+
case (let _k1?, nil):
595595
XCTFail("\(prefix) CodingKey mismatch: \(type(of: _k1)) != nil")
596596
return
597-
case (.none, .some(let _k2)):
597+
case (nil, let _k2?):
598598
XCTFail("\(prefix) CodingKey mismatch: nil != \(type(of: _k2))")
599599
return
600600
default: break
@@ -604,14 +604,14 @@ func expectEqualPaths(_ lhs: [CodingKey?], _ rhs: [CodingKey?], _ prefix: String
604604
let key2 = k2!
605605

606606
switch (key1.intValue, key2.intValue) {
607-
case (.none, .none): break
608-
case (.some(let i1), .none):
607+
case (nil, nil): break
608+
case (let i1?, nil):
609609
XCTFail("\(prefix) CodingKey.intValue mismatch: \(type(of: key1))(\(i1)) != nil")
610610
return
611-
case (.none, .some(let i2)):
611+
case (nil, let i2?):
612612
XCTFail("\(prefix) CodingKey.intValue mismatch: nil != \(type(of: key2))(\(i2))")
613613
return
614-
case (.some(let i1), .some(let i2)):
614+
case (let i1?, let i2?):
615615
guard i1 == i2 else {
616616
XCTFail("\(prefix) CodingKey.intValue mismatch: \(type(of: key1))(\(i1)) != \(type(of: key2))(\(i2))")
617617
return

0 commit comments

Comments
 (0)