Skip to content

Commit a8b707f

Browse files
committed
Eliminate switch-must-be-exhaustive warning in Apple sign-in handler
Replace the switch over ASAuthorizationError.Code with an if/else cascade. ASAuthorizationError.Code is non-frozen and gains new cases (notInteractive in 15.4, matchedExcludedCredential in 18.0, credentialImport / credentialExport in 18.2) that can only be referenced behind #available. With a switch, this trips "switch must be exhaustive" even with @unknown default, because the compiler sees those known cases at compile time but they aren't listed explicitly. An if-cascade has no exhaustiveness requirement and stays readable. The project-level IPHONEOS_DEPLOYMENT_TARGET = 10.0 (out-of-range) warning is left in place for now — the IFTTTConnectSDK target inherits that value, and bumping it surfaces real dead-code paths (SFWebService and ConnectionVerificationSession's iOS 11 fallback) that need a separate refactor to delete.
1 parent 474dfc0 commit a8b707f

1 file changed

Lines changed: 26 additions & 35 deletions

File tree

IFTTT SDK/SignInWithAppleAuthentication.swift

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,33 @@ final class AppleSignInWebService: ServiceAuthentication {
4040

4141
@available(iOS 13.0, *)
4242
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
43-
let authorizationError = ASAuthorizationError(_nsError: error as NSError)
44-
// Cases added after the SDK's iOS 14.2 deployment target.
45-
// Each is referenced behind an availability check and mapped
46-
// to the matching AuthenticationError case so callers can
47-
// distinguish it from the generic .failed / .unknown bucket.
48-
if #available(iOS 15.4, *), authorizationError.code == .notInteractive {
49-
completion(.failure(.notInteractive))
50-
return
51-
}
52-
if #available(iOS 18.0, *), authorizationError.code == .matchedExcludedCredential {
53-
completion(.failure(.matchedExcludedCredential))
54-
return
55-
}
56-
if #available(iOS 18.2, *), authorizationError.code == .credentialImport {
57-
completion(.failure(.credentialImport))
58-
return
59-
}
60-
if #available(iOS 18.2, *), authorizationError.code == .credentialExport {
61-
completion(.failure(.credentialExport))
62-
return
63-
}
64-
65-
switch authorizationError.code {
66-
case .canceled:
67-
completion(.failure(.userCanceled))
68-
case .failed:
69-
completion(.failure(.failed))
70-
case .invalidResponse:
71-
completion(.failure(.invalidResponse))
72-
case .notHandled:
73-
completion(.failure(.notHandled))
74-
case .unknown:
75-
completion(.failure(.unknown))
76-
@unknown default:
77-
completion(.failure(.unknown))
43+
let code = ASAuthorizationError(_nsError: error as NSError).code
44+
// If/else cascade rather than a switch: ASAuthorizationError.Code is
45+
// non-frozen and gains new cases (notInteractive in 15.4, ...) that
46+
// can only be referenced behind #available — a switch over them
47+
// either trips "switch must be exhaustive" warnings or requires
48+
// raising the deployment target.
49+
let mapped: AuthenticationError
50+
if code == .canceled {
51+
mapped = .userCanceled
52+
} else if code == .failed {
53+
mapped = .failed
54+
} else if code == .invalidResponse {
55+
mapped = .invalidResponse
56+
} else if code == .notHandled {
57+
mapped = .notHandled
58+
} else if #available(iOS 15.4, *), code == .notInteractive {
59+
mapped = .notInteractive
60+
} else if #available(iOS 18.0, *), code == .matchedExcludedCredential {
61+
mapped = .matchedExcludedCredential
62+
} else if #available(iOS 18.2, *), code == .credentialImport {
63+
mapped = .credentialImport
64+
} else if #available(iOS 18.2, *), code == .credentialExport {
65+
mapped = .credentialExport
66+
} else {
67+
mapped = .unknown
7868
}
69+
completion(.failure(mapped))
7970
}
8071
}
8172

0 commit comments

Comments
 (0)