Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Facebook Announces Open-Source Swift SDK Beta for iOS

Facebook Announces Open-Source Swift SDK Beta for iOS

This item in japanese

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


  pod 'FacebookCore'
  pod 'FacebookLogin'
  pod 'FacebookShare'

  ## other pod files here as required

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 {
} 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.

Rate this Article