gpt4 book ai didi

swift - 无法将类型 'String?' 的值转换为预期的参数类型 '_?'

转载 作者:行者123 更新时间:2023-11-28 13:29:54 30 4
gpt4 key购买 nike

作为我在 Amazon Cognito 中设置身份验证工作的一部分,我正在实现一个函数来检索自定义身份提供商的 IdentityID 和 token 。我需要将 token 添加为返回语句的一部分,但在返回语句中出现错误。
“无法转换‘字符串’类型的值?”到预期的参数类型“_?”。

我不明白什么_?论据究竟是什么以及如何符合它。

import AWSCore
/*
* Use the token method to communicate with your backend to get an
* identityId and token.
*/
class DeveloperAuthenticatedIdentityProvider : AWSCognitoCredentialsProviderHelper {
override func token() -> AWSTask<NSString> {
//Write code to call your backend:
//pass username/password to backend or some sort of token to authenticate user, if successful,
//from backend call getOpenIdTokenForDeveloperIdentity with logins map containing "your.provider.name":"enduser.username"
//return the identity id and token to client
//You can use AWSTaskCompletionSource to do this asynchronously

// Set the identity id and return the token
self.identityId = resultFromAbove.identityId
return AWSTask(result: resultFromAbove.token)
}

resultFromAbove.token 是 String?.所以当我使用它时,我得到了错误。但是,如果我只是输入一个字符串,例如

return AWSTask(result: "abcd")

这似乎没问题。我在这里缺少什么?

最佳答案

改变

return AWSTask(result: resultFromAbove.token)

return AWSTask(result: resultFromAbove.token as NSString?)

关于swift - 无法将类型 'String?' 的值转换为预期的参数类型 '_?',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57545614/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com