LinkedIn SDK ios swift

我正在尝试使用swift在iOS中集成LinkedIn SDK

我在Objective-C中find了下面的代码( https://developer.linkedin.com/docs/signin-with-linkedin )

NSString *url = [NSString initWithString:@"https://api.linkedin.com/v1/people/~"]; if ([LISDKSessionManager hasValidSession]) { [[LISDKAPIHelper sharedInstance] getRequest:url success:^(LISDKAPIResponse *response) { // do something with response } error:^(LISDKAPIError *apiError) { // do something with error }]; ]} 

如何将其转换为swift。

我很新,很快

 var url = NSString(string:"https://api.linkedin.com/v1/people/~") if LISDKSessionManager.hasValidSession { LISDKAPIHelper.sharedInstance().getRequest(url, success: { response in //Do something with the response }, error: { error in //Do something with the error }) } 

这(我认为是正确的)是翻译版本。 我不知道Objective-C,我只是用我的Swift知识来尝试解决这个问题。

你有没有学习closures? 如果没有,我不推荐使用像LinkedIn这样的SDK,因为它们依赖于closures许多networking请求。 我会检查Treehouse Inc. ,一个编码课程网站,它提供关于在Swift中closures的伟大课程(以及其他一些东西)。

 var url = "https://api.linkedin.com/v1/people/~" if LISDKSessionManager.hasValidSession() { try? LISDKAPIHelper.sharedInstance().getRequest(url, success: {(_ response: LISDKAPIResponse) -> Void in // do something with response }) } 

这是迅速的4