Now available in beta, Facebook’s new SDK for Swift aims to make it easier for developers to integrate Facebook services into their iOS apps.
Facebook Swift SDK for Swift includes support for a number of Facebook services, including Facebook Analytics, Facebook Login, Share for Facebook, and Facebook Graph API. It is based on the existing Objective-C Facebook SDK, around which it builds a collection of wrappers aiming to provide a native Swift API and easier developer experience.
Facebook Swift SDK includes support for the two most popular package management systems for iOS/macOS, CocoaPods and Carthage. To include it into your app using CocoaPods, ensure your Podfile looks something like this:
target "YourXcodeTargetNameHere" do
use_frameworks!
pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'
## other pod files here as required
end
If you use Carthage, you can add the following line to your Cartfile:
github "facebook/Facebook-SDK-Swift"
Alternatively, you can include Facebook Swift SDK as a subproject into your Xcode project, although this approach will require you to take care of all dependencies, namely FBSDKCoreKit.framework
, FBSDKLoginKit.framework
, and FBSDKShareKit.framework
, and their updates.
Facebook Swift SDK repo on GitHub includes a sample project showing how you can integrate supported services into your app. This is for example how you can share a photo using the provided ShareDialogViewController
:
let photo = Photo(image: UIImage(named: "sky.jpg")!, userGenerated: true)
let content = PhotoShareContent(photos: [photo])
let dialog = ShareDialog(content: content)
dialog.presentingViewController = self
dialog.mode = .Automatic
do {
try dialog.show()
} catch (let error) {
let alertController = UIAlertController(title: "Invalid share content", message: "Failed to present share dialog with error \(error)")
presentViewController(alertController, animated: true, completion: nil)
}
Facebook Swift SDK targets Swift 2.2.1 and 2.3, allowing thus developers to submit apps to the App Store, while support for Swift 3 is scheduled for later this year when Swift 3 reaches GM.
Community comments
Doesn't work
by Dylan Fernando,
Re: Doesn't work
by James Hubert,
Re: Doesn't work
by Sergio De Simone,
Re: Doesn't work
by Sergio De Simone,
Re: Doesn't work
by Fabiola Werneck,
reply
by shalini ranganathan,
use_frameworks!
by Joe Parks,
Doesn't work
by Dylan Fernando,
Your message is awaiting moderation. Thank you for participating in the discussion.
Unable to find a specification for `FacebookCore`
reply
by shalini ranganathan,
Your message is awaiting moderation. Thank you for participating in the discussion.
your coding and sayings are really awesome and thus it is very much useful and it is highly relevant
Re: Doesn't work
by James Hubert,
Your message is awaiting moderation. Thank you for participating in the discussion.
Have you figured this out? I'm having the same issue.
use_frameworks!
by Joe Parks,
Your message is awaiting moderation. Thank you for participating in the discussion.
Have you tried it with the "use_frameworks!" directive?
From the getting started guide:
Re: Doesn't work
by Sergio De Simone,
Your message is awaiting moderation. Thank you for participating in the discussion.
I guess you did not specify a target in your Podfile. That should go like this:
Re: Doesn't work
by Sergio De Simone,
Your message is awaiting moderation. Thank you for participating in the discussion.
Please, see my reply to Dylan Fernando. Hope it helps.
Re: Doesn't work
by Fabiola Werneck,
Your message is awaiting moderation. Thank you for participating in the discussion.
Hey! Just update the cocoapods version using
sudo gem install cocoapods
command.
Facebook SDK in Swift supports CocoaPods 1.0.1 or later.
;)