0

My name is Nicolás and I am learning how to develop apps for iOS using swift. I need an advice on how to save the user information I retrieve from Facebook Login in order to use it from any view (I was able to use fb login thanks to this tutorial). I tried passing this information through segues but I couldn't achieve this (I recibe this error: Use of unresolved identifier 'userName'). I was thinking maybe something like creating a "global variable" (If they exist in Swift) would be a better practice.

Here is the code of my view controller:

import UIKit

class ViewController: UIViewController, FBLoginViewDelegate {

    @IBOutlet var fbLoginView : FBLoginView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.fbLoginView.delegate = self
        self.fbLoginView.readPermissions = ["public_profile", "email", "user_friends"]

    }

    // FACEBOOK DELEGATE METHODS
    func loginViewShowingLoggedInUser(loginView : FBLoginView!) {
        println("User Logged In")
        println("This is where you perform a segue.")
        self.performSegueWithIdentifier("gotoview2", sender: self)
    }


func loginViewFetchedUserInfo(loginView : FBLoginView!, user: FBGraphUser){
    var userName = user.name

}

func loginViewShowingLoggedOutUser(loginView : FBLoginView!) {
    println("User Logged Out")
}

func loginView(loginView : FBLoginView!, handleError:NSError) {
    println("Error: \(handleError.localizedDescription)")
}


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        if (segue.identifier == "gotoView2") {
             let viewController:SecondViewController = segue!.destinationViewController as SecondViewController
            viewController.name = userName // !! HERE IS WHERE I RECIBE THE ERROR !!
        }
    }

}

Thanks you all very much for your help. I am new to this world and the fact that Swift is so new doesn't helps.

Greetings, Nico

NMO
  • 293
  • 1
  • 10
  • Use NSUserDefaults for this. – Amit Aug 30 '14 at 06:06
  • possible duplicate of [Passing Facebook user information between views. iOS Swift Xcode 6](http://stackoverflow.com/questions/25562467/passing-facebook-user-information-between-views-ios-swift-xcode-6) – jtbandes Aug 30 '14 at 06:37
  • This seems to have very little difference from your earlier question. Did you see the other question which yours was marked as a duplicate of? This type of question has been asked and answered before; if you have a more specific problem then you should ask that specifically. – jtbandes Aug 30 '14 at 06:42

0 Answers0