noobdev noobdev - 7 months ago 23
Swift Question

Converting swift 1.2 code to swift 2: Missing argument label in call

I'm receiving a "Missing argument label 'rawValue:' in call" error while trying to set the authorisation header for an API authentication project based on this tutorial (https://www.raywenderlich.com/85528/user-accounts-ios-ruby-rails-swift#next_section).

This is the code in question with the issue at the

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:
// Retreieve 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")
}
}


The full code can be found here (https://codeshare.io/uJPcX) at line 50

Answer

Change:

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

to:

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