Skip to content

Commit bbd5283

Browse files
committed
macOS Build fix: TestURL
The catches _are_ exhaustive, and the cast to NSError will never fail, but since it is SwiftFoundation.NSError (and not ObjC NSError) the macOS build cannot detect that. Fix by catching all errors instead.
1 parent 95fcab2 commit bbd5283

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

TestFoundation/TestURL.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,29 @@ class TestURL : XCTestCase {
244244

245245
do {
246246
try FileManager.default.removeItem(atPath: gFileDoesNotExistPath)
247-
} catch let error as NSError {
247+
} catch {
248248
// The error code is a CocoaError
249-
if error.code != CocoaError.fileNoSuchFile.rawValue {
249+
if (error as? NSError)?.code != CocoaError.fileNoSuchFile.rawValue {
250250
return false
251251
}
252252
}
253253

254254
do {
255255
try FileManager.default.createDirectory(atPath: gDirectoryExistsPath, withIntermediateDirectories: false)
256-
} catch let error as NSError {
257-
// The error code is a CocoaError
258-
if error.code != CocoaError.fileWriteFileExists.rawValue {
259-
return false
260-
}
256+
} catch {
257+
// The error code is a CocoaError
258+
if (error as? NSError)?.code != CocoaError.fileNoSuchFile.rawValue {
259+
return false
260+
}
261261
}
262262

263263
do {
264264
try FileManager.default.removeItem(atPath: gDirectoryDoesNotExistPath)
265-
} catch let error as NSError {
266-
// The error code is a CocoaError
267-
if error.code != CocoaError.fileNoSuchFile.rawValue {
268-
return false
269-
}
265+
} catch {
266+
// The error code is a CocoaError
267+
if (error as? NSError)?.code != CocoaError.fileNoSuchFile.rawValue {
268+
return false
269+
}
270270
}
271271

272272
#if os(Android)

0 commit comments

Comments
 (0)