Using the Facebook iOS SDK in Swift

Just a quick video to show you how to use the facebook native ios sdk in swift.

follow the directions to get your plist file updated here:

Once that’s done follow the instructions to add your build identity to facebooks records. Then…

  1. drag the frameworks into your project
  2. update your appdelegate file
  3. update your view controller
  4. make your view controller a delegate for the login button
  5. test

replace your applicationdidlaunchwithoptions:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

Then add the following:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)

Then in your “applicationDidBecomeActive“:


NOTE: make sure to import:

import FBSDKCoreKit
//  ViewController.swift
//  FacebookTutorial
//  Created by Mike Newell on 8/13/15.
//  Copyright (c) 2015 Mike Newell. All rights reserved.

import UIKit
import FBSDKCoreKit
import FBSDKLoginKit

class ViewController: UIViewController, FBSDKLoginButtonDelegate {

    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.
        if FBSDKAccessToken.currentAccessToken() != nil {
            // user already has access token
        } else {
            let loginButton = FBSDKLoginButton()
            loginButton.readPermissions = ["email"]
            loginButton.delegate = self

    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated.
    override func viewWillAppear(animated: Bool) {
    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        println("logged in")
    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
        println("logged out")
    func logUserData() {
        let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
        graphRequest.startWithCompletionHandler { (connection, result, error) -> Void in
            if error != nil {
            } else {


That’s it! here’s a video explaining more:

There’s also a great tutorial for anyone looking to do the older “bridging” method of importing the sdk:

3 thoughts on “Using the Facebook iOS SDK in Swift

  1. Hello,
    Great post and video. I was able to get logged in by the end of the video thanks! I do have a question. I am very new to ios, I have been coding C# for a few years and would like to start working on some apps that I have in mind but I can’t seem to be able to post a image to facebook. I have been able to get a message to post through the sdk but not an image. Have you dont that yet? If so could you please share the code . Thanks again.

  2. Hi, Nice tutorial.

    I already add all those required framework. But when I put ‘Import FBSDKCoreKit’ in my AppDelegate.Swift, it shows an error and state that “No such module FBSDKCoreKit”.

    What’s wrong with my code?

Leave a Reply

Your email address will not be published. Required fields are marked *