Title: Open FBSession in Swift
Tags: ios;xcode;facebook;swift
Question: How can i open an new FBSession in Swift? I have a Facebook login currently that is working perfect, and now i want to get the friends in a new controller.
I currently have this:
var friendsRequest : FBRequest = FBRequest.requestForMyFriends()
friendsRequest.startWithCompletionHandler{(connection:FBRequestConnection!, result:AnyObject!, error:NSError!) -&gt; Void in
var resultdict = result as NSDictionary
println("dict: \(resultdict)")
var data : NSArray = resultdict.objectForKey("data") as NSArray
for i in 0...data.count {
let valueDict : NSDictionary = data[i] as NSDictionary
let id = valueDict.objectForKey("id") as String
println("id \(id)")
}
var friends = resultdict.objectForKey("data") as NSArray
println("\(friends.count) friends")
And this is giving me this error:
FBSDKLog: Error for request to endpoint 'me/friends': An open FBSession must be specified for calls to this endpoint.
How can i achieve this? I can't seem to find this..


Here is another answer: var friendsRequest : FBRequest = FBRequest.requestForMyFriends()
friendsRequest.startWithCompletionHandler{(connection:FBRequestConnection!,     result:AnyObject!, error:NSError!) -&gt; Void in
var resultdict = result as NSDictionary
println("Result Dict: \(resultdict)")
var data : NSArray = resultdict.objectForKey("data") as NSArray
for i in 0...data.count {
let valueDict : NSDictionary = data[i] as NSDictionary
let id = valueDict.objectForKey("id") as String
println("the id value is \(id)")
var friends = resultdict.objectForKey("data") as NSArray
println("Found \(friends.count) friends")

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:11/03/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<ios><xcode><facebook><swift>', 'Title': 'Open FBSession in Swift', 'ViewCount': 365, 'id': 26710622, 'user_AboutMe': None, 'user_AccountId': 5102455.0, 'user_DisplayName': 'EricDXS', 'user_Reputation': 882.0, 'user_Views': 18.0, 'user_id': 4091676.0}}