This is a wrinkle on the regular NSURLSession completion block problem, which I'm having a heck of a time resolving into Swift syntax. The method is the authentication delegate callback, which is invoked on auth challenge; the developer calls the completion block with NSURLCredential, NSError.
The Objective-C method looks like this:
-(void) provideUsernamePasswordForAuthChallenge:(NSURLAuthenticationChallenge *)authChallenge completionHandler:(void (^)(NSURLCredential *, NSError *))completionHandler{
NSURLCredential* credential = [NSURLCredential credentialWithUser:@"myname"
password:@"mypass"
persistence:NSURLCredentialPersistenceForSession];
completionHandler(credential, nil);
}
The closest I think I've gotten in Swift, is this:
func provideUsernamePasswordForAuthChallenge(authChallenge: NSURLAuthenticationChallenge!, completionHandler:(() -> (NSURLCredential?, NSError?)) {
var cred = NSURLCredential(user: "myname", password: "mypass", persistence: NSURLCredentialPersistence.ForSession)
return (cred, nil)
})
But, it's still barfing. Any recommendations?