So im a bit new to swift and object-c as well and was wondering if someone could help me out a bit.
I'm used to creating usually a utils file where I have functions I use often in programming.
In this case im trying to call a function from another swift file and return an array of data.
For example in my mainViewController.swift im calling the function:
var Data = fbGraphCall()
In the Utils.swift file I have a function that Im trying to get it to return an array of data collected.
func fbGraphCall() -> Array<String>{
var fbData: [String] = [""]
if (FBSDKAccessToken.currentAccessToken() != nil){
// get fb info
var userProfileRequestParams = [ "fields" : "id, name, email, about, age_range, address, gender, timezone"]
let userProfileRequest = FBSDKGraphRequest(graphPath: "me", parameters: userProfileRequestParams)
let graphConnection = FBSDKGraphRequestConnection()
graphConnection.addRequest(userProfileRequest, completionHandler: { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if(error != nil) {
println(error)
} else {
// DEBUG
println(result)
let fbEmail = result.objectForKey("email") as! String
// DEBUG
println(fbEmail)
fbData.append("\(fbEmail)")
let fbID = result.objectForKey("id") as! String
if(fbEmail != "") {
PFUser.currentUser()?.username = fbEmail
PFUser.currentUser()?.saveEventually(nil)
}
println("Email: \(fbEmail)")
println("FBUserId: \(fbID)")
}
})
graphConnection.start()
}
println(fbData)
return fbData
}
I can confirm that im getting the fbEmail and fbID back from facebook with my debug statements but as I said im still new on how to return data back.
Ideally I usually want an array back if its more than one value or the ability to get back data like Data.fbEmail, Data.fbID or an array maybe like ["email" : "[email protected]", "id" : "1324134124zadfa"]
When I hit the return statement its blank.. so not sure why the constants are not keeping values or passing values into my fbData array.. I'm trying fbData.append(fbEmail) for example ..
any thoughts on what might be wrong?