gpt4 book ai didi

swift - 如何通过 Result 类型的实例获取值?

转载 作者:行者123 更新时间:2023-11-30 11:07:16 24 4
gpt4 key购买 nike

在我的应用程序中使用 auth0对于登录和成功登录后,我在回调中获取数据类型 Result<Credentials> 的对象现在我需要 Credentials 中的值我怎样才能得到那个。物体没有远距感。函数名称是 func start(_ callback: @escaping (Result<Credentials>) -> Void)我的代码是

wa.start { (result) in
print(result)
let acb = result
}

where Result object have

public enum Result<T> {
case success(result: T)
case failure(error: Error)
}

and Credentials Object have

@objc public let accessToken: String?
@objc public let tokenType: String?

最佳答案

Result 是一个 enum,因此您可以在它的实例上switch...

wa.start { result in
switch result {
case let .success(credentials):
// Handle your credentials here…
case let .failure(error):
// Present an error
}
}

关于swift - 如何通过 Result<Credentials> 类型的实例获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52567565/

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