Nikolai’s decision is wonderful. Here is his Swift Version
func makeFBRequestToPath(aPath:String, withParameters:Dictionary<String, AnyObject>, success successBlock: (Array<AnyObject>?) -> (), failure failureBlock: (NSError?) -> ())
{
let recievedDataStorage:Array<AnyObject> = Array<AnyObject>()
p_requestFromPath(aPath, parameters: withParameters, storage: recievedDataStorage, success: successBlock, failure: failureBlock)
}
func p_requestFromPath(path:String, parameters params:Dictionary<String, AnyObject>, var storage friends:Array<AnyObject>, success successBlock: (Array<AnyObject>?) -> (), failure failureBlock: (NSError?) -> ())
{
let req = FBSDKGraphRequest(graphPath: path, parameters: params, tokenString: FBSDKAccessToken.currentAccessToken().tokenString, version: nil, HTTPMethod: "GET")
req.startWithCompletionHandler({ (connection, result, error : NSError!) -> Void in
if(error == nil)
{
print("result \(result)")
let result:Dictionary<String, AnyObject> = result as! Dictionary<String, AnyObject>
friends.append(result["data"]!)
let nextCursor:String? = result["paging"]!["next"]! as? String
if let _ = nextCursor
{
let paramsOfNextPage:Dictionary = FBSDKUtility.dictionaryWithQueryString(nextCursor!)
if paramsOfNextPage.keys.count > 0
{
self.p_requestFromPath(path, parameters: paramsOfNextPage as! Dictionary<String, AnyObject>, storage: friends, success:successBlock, failure: failureBlock)
return
}
}
successBlock(friends)
}
else
{
print("error \(error)")
failureBlock(error)
}
})
}
func getFBFriendsList()
{
let anyParametersYouWant:Dictionary = ["limit":2]
makeFBRequestToPath("/me/friends/", withParameters: anyParametersYouWant, success: { (results:Array<AnyObject>?) -> () in
print("Found friends are: \(results)")
}) { (error:NSError?) -> () in
print("Oops! Something went wrong \(error)")
}
}
source
share