gpt4 book ai didi

ios - 将 swift 1.2 代码转换为 swift 2 : Missing argument label in call

转载 作者:行者123 更新时间:2023-11-28 06:44:12 30 4
gpt4 key购买 nike

尝试根据本教程 (https://www.raywenderlich.com/85528/user-accounts-ios-ruby-rails-swift#next_section) 为 API 身份验证项目设置授权 header 时,出现“调用中缺少参数标签‘rawValue:’”错误。

这是有问题的代码

let base64EncodedString = utf8str?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(0))

完整代码:

switch authType {
case .HTTPBasicAuth:
// Set BASIC authentication header
let basicAuthString = "\(HTTPHelper.API_AUTH_NAME):\(HTTPHelper.API_AUTH_PASSWORD)"
let utf8str = basicAuthString.dataUsingEncoding(NSUTF8StringEncoding)
let base64EncodedString = utf8str?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(0))

request.addValue("Basic \(base64EncodedString!)", forHTTPHeaderField: "Authorization")
case .HTTPTokenAuth:
// Retrieve Auth_Token from Keychain
if let userToken = KeychainAccess.passwordForAccount("Auth_Token", service: "KeyChainService") as String? {
// Set Authorization header
request.addValue("Token token=\(userToken)", forHTTPHeaderField: "Authorization")
}
}

完整代码可以在此处 ( https://codeshare.io/uJPcX ) 第 50 行找到

最佳答案

改变:

let base64EncodedString = utf8str?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(0))

到:

let base64EncodedString = utf8str?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))

关于ios - 将 swift 1.2 代码转换为 swift 2 : Missing argument label in call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37017702/

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