I need to add the LinkedIn SDK into my Swift project. I've downloaded their latest version (1.0.4), dragged and dropped the SDK files into XCode (with "Copy items if needed" and "Add to target" checked). I can see the framework in the "Linked Frameworks and Libraries" section of my target.
I'm stuck though when I need to import the headers in one swift file. There is an Objective C example in the LinkedIn documentation:
#import <linkedin-sdk/LISDK.h>
But how would you do it in Swift? I've tried different names but they all raise an error.
import LinkedIn
import LISDK
"import linkedin-sdk" fails because of the dash ( - ).
I've already imported external frameworks in my project (Parse for instance) and it perfectly worked.
Thanks for the help!
EDIT I do not use LinkedIn API anymore, for they have stopped sharing useful information. Anyway, here is an old sample of code:
var accessToken: LISDKAccessToken?
func loadAccount(then: (() -> Void)?, or: ((String) -> Void)?) { // then & or are handling closures
if let token = accessToken {
LISDKSessionManager.createSessionWithAccessToken(token)
if LISDKSessionManager.hasValidSession() {
LISDKAPIHelper.sharedInstance().getRequest("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,formatted-name,headline,location,industry,current-share,num-connections,num-connections-capped,summary,specialties,positions,picture-url,picture-urls::(original))?format=json",
success: {
response in
print(response.data)
then?()
},
error: {
error in
print(error)
or?("error")
}
)
}
} else {
LISDKSessionManager.createSessionWithAuth([LISDK_BASIC_PROFILE_PERMISSION], state: nil, showGoToAppStoreDialog: true,
successBlock: {
(state) in
self.accessToken = LISDKSessionManager.sharedInstance().session.accessToken
if LISDKSessionManager.hasValidSession() {
LISDKAPIHelper.sharedInstance().getRequest("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,formatted-name,headline,location,industry,current-share,num-connections,num-connections-capped,summary,specialties,positions,picture-url,picture-urls::(original))?format=json",
success: {
response in
print(response.data)
then?()
},
error: {
error in
print(error)
or?("error")
}
)
}
},
errorBlock: {
(error) in
switch error.code {
default:
if let errorUserInfo = error.userInfo["error"] as? NSString {
or?(errorUserInfo as String)
} else {
or?(UIError.Code.Unknown)
}
}
}
)
}
}
Man, you should have a bridging header. Mine looks as simple as that:
// Copyright © 2015 Arthur Gevorkyan. All rights reserved.
//
#ifndef BridgingHeader_h
#define BridgingHeader_h
#import <Foundation/Foundation.h>
#import <linkedin-sdk/LISDK.h>
#endif /* BridgingHeader_h */