ios - Get array of facebook albums in swift using Facebook SDK 4.1 -
i'm attempting fetch array of users facebook albums via new facebook sdk 4.1 using following swift code:
func getalbumlist() { var fbalbums = [string]() let graphrequest : fbsdkgraphrequest = fbsdkgraphrequest(graphpath: "me?fields=albums", parameters: nil) graphrequest.startwithcompletionhandler({ (connection, result, error) -> void in if ((error) != nil) { // process error println("error: \(error)") } else { println("fetched data: \(result)") let graphdata = result.valueforkey("data") array; obj:fbgraphobject in graphdata{ let desc = obj.description; println(desc); let name = obj.valueforkey("name") string; println(name); } } }) }
the fb sdk query working ok result value contains data facebook (it prints fine), attempt turn array failling.
using xcode 6.3 gives following errors:
let graphdata = result.valueforkey("data") array;
= 'anyobject?' not convertible 'array<t>'
for obj:fbgraphobject in graphdata{
= use of undeclared type 'fbgraphobject'
i can't seem find information has replaced fbgraphobject, or why can't convert result array.
articles used background (but out of date seems):
creating array of objects facebook sdk in swift
http://selise.ch/build-a-facebook-album-browser-using-swift/
just change line of code:
let graphdata = result.valueforkey("data") array;
to:
self.dict = result["data"] as! nsarray
this works me retrieving user photos facebook:
fbsdkgraphrequest(graphpath: "me/photos", parameters: ["fields": "id, name, source"]).startwithcompletionhandler({ (connection, result, error) -> void in if (error == nil){ self.dict = result["data"] as! nsarray item in self.dict { // loop through data items if let urlstring = item["source"]! { let url = nsurl(string: urlstring as! string) let imagedata = nsdata(contentsofurl: url!) let image = uiimage(data: imagedata!) self.socialphotocollection.append(image!) } } } })
Comments
Post a Comment