2015-11-25 8 views
0

Je suis actuellement en train de suivre le tutoriel de Spotify sur iOS SDK. Je convertis également le code Objective-C t Swift.Erreur dans le tutoriel du SDK iOS de Spotify

Spotify veut exécuter ce code:

-(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; 
} 

J'ai converti à 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 
    } 

Le code rapide, cependant, contient 2 erreurs:

1) enter image description here Pourquoi ai-je une erreur en suivant le didacticiel de Spotify?

S'agit-il de convertir Objective-C en Swift? Comment pourrais-je résoudre ce problème?

2) enter image description here

+0

Je vous recommande de faire un commentaire sur le [tutoriel iOS SDK page] (https://developer.spotify.com/technologies/spotify-ios-sdk/tutorial /) (en bas, cliquez sur "Afficher les commentaires") puisque c'est l'endroit approprié pour signaler des problèmes avec le tutoriel. –

Répondre

1

Lorsque vous manipulez le callback, vous jettent l'erreur comme NSErrorPointer plutôt que NSError.

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

devrait être

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