1

Would anyone be able to explain this method that we should invoke to recieve the friend list?

var fbRequestFriends: FBRequest = FBRequest.requestForMyFriends()

fbRequestFriends.startWithCompletionHandler{
    (connection:FBRequestConnection!,result:AnyObject?, error:NSError!) -> Void in
}

Specifically this line

(connection:FBRequestConnection!,result:AnyObject?, error:NSError!) -> Void in

It seems to me like we are calling a function "startWithCompletionHandler", after that I am lost to be honest. I can't understand what happens next. Can anyone please explain this?

Edit: I understand this is the way to implement it. I'm Actually looking for an intuitive explanation like in this answer: Method Syntax in Objective C

Community
  • 1
  • 1
mtisz
  • 1,000
  • 10
  • 11

2 Answers2

3

you can use below code to get the friend list

  // Get List Of Friends
  var friendsRequest : FBRequest = FBRequest.requestForMyFriends()
  friendsRequest.startWithCompletionHandler
 {
     (connection:FBRequestConnection!,   result:AnyObject!, error:NSError!) -> 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")
 }
Vikram Pote
  • 5,433
  • 4
  • 33
  • 37
0

Well you can see the result of your request call in the closure that you are passing in . Try printing the result object to console like below .

var fbRequestFriends: FBRequest = FBRequest.requestForMyFriends()

fbRequestFriends.startWithCompletionHandler{
(connection:FBRequestConnection!,result:AnyObject?, error:NSError!) -> Void in

    if error == nil && result != nil { 
    println("Request Friends result : \(result!)")
    } else {
    println("Error \(error)") 
   }
}

I have not worked with Swift sdk for Facebook yet but I think result object should be an array of facebook user objects ( friends ) .

Bharat Jagtap
  • 1,692
  • 2
  • 22
  • 35