Spotify iOS SDK 教程中的错误

Error in Spotify's iOS SDK tutorial

我目前正在学习 Spotify 关于 iOS SDK 的教程。我也在转换 Objective-C 代码 t Swift.

Spotify 要我运行这个代码:

-(BOOL)application:(UIApplication *)application
           openURL:(NSURL *)url
 sourceApplication:(NSString *)sourceApplication
        annotation:(id)annotation {

    // Ask SPTAuth if the URL given is a Spotify authentication callback
    if ([[SPTAuth defaultInstance] canHandleURL:url]) {
        [[SPTAuth defaultInstance] handleAuthCallbackWithTriggeredAuthURL:url callback:^(NSError *error, SPTSession *session) {

             if (error != nil) {
                 NSLog(@"*** Auth error: %@", error);
                 return;
             }

             // Call the -playUsingSession: method to play a track
             [self playUsingSession:session];
        }];
        return YES;
    }

    return NO;
}

我已经把它转换成Swift:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
        if SPTAuth.defaultInstance().canHandleURL(url) {
            SPTAuth.defaultInstance().handleAuthCallbackWithTriggeredAuthURL(url, callback: {(error: NSErrorPointer, session: SPTSession) -> Void in
                if error != nil {
                    NSLog("*** Auth error: %@", error)
                    return
                }
                playUsingSession(session)
            })
            return true
        }
        return false
    }

然而,swift 代码包含 2 个错误:

1)

为什么我在按照 Spotify 的教程进行操作时出现错误?与将Objective-C转换为Swift有关吗?我该如何解决这个问题?

2)

当您处理 callback 时,您将错误转换为 NSErrorPointer 而不是 NSError

SPTAuth.defaultInstance().handleAuthCallbackWithTriggeredAuthURL(url, callback: {(error: NSErrorPointer, session: SPTSession) -> Void in
                if error != nil {
                    NSLog("*** Auth error: %@", error)
                    return
                }
                playUsingSession(session)
 }) 

应该是

SPTAuth.defaultInstance().handleAuthCallbackWithTriggeredAuthURL(url, callback: {(error: NSError, session: SPTSession) -> Void in
                if error != nil {
                    NSLog("*** Auth error: %@", error)
                    return
                }
                playUsingSession(session)
 })