I have defined the following functions:
func createAccessControl() -> Future<SecAccessControl, Error>
func evaluatePolicy(context: LAContext, localizedReason: String) -> Future<LAContext, Error>
func evaluateAccessControl(
context: LAContext,
accessControl: SecAccessControl,
operation: LAAccessControlOperation,
localizedReason: String
) -> Future<LAContext, Error>
func copy(query: [String: Any]) -> Future<Data, Error>
And I want to chain them together like this:
func load(key: String, context: LAContext = LAContext(), localizedReason: String) -> Future<Data, Error> {
createAccessControl().flatMap { accessControl in
evaluatePolicy(context: context, localizedReason: localizedReason)
.flatMap { context in
evaluateAccessControl(context: context, accessControl: accessControl, operation: .useItem, localizedReason: localizedReason)
}
.flatMap { context in
copy(query: [
kSecClass as String: kSecClassGenericPassword as String,
kSecAttrService as String: service,
kSecAttrAccount as String: account,
kSecAttrAccessControl as String: accessControl,
kSecUseAuthenticationContext as String: context,
kSecReturnData as String: kCFBooleanTrue,
kSecMatchLimit as String: kSecMatchLimitOne,
])
}
}
}
However, I get this error:
Cannot convert return expression of type 'Publishers.FlatMap<Publishers.FlatMap<Future<Data, Error>, Publishers.FlatMap<Future<LAContext, Error>, Future<LAContext, Error>>>, Future<SecAccessControl, Error>>' to return type 'Future<Data, Error>'
I thought flatMap
was supposed to flatten the resulting type, but that doesn't seem to be happening the way I expect.
How do I chain futures together, similar to JavaScript's "then"?