我可以检索并显示姓名,生日,电子邮件和图片。
我可以检索工作数据,因为它打印得很好。
我的问题是我如何能够在标签中显示雇主姓名和职位名称等特定内容。
func showUserData()
{
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "id, first_name, birthday, work, email, picture.type(large)"])
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil)
{
// Process error
print("Error: \(error)")
}
else
{
// Request firstname
let userName : NSString = result.valueForKey("first_name") as! NSString
// Request birthdate
let userBirthday : NSString = result.valueForKey("birthday") as! NSString
// Request work info
let userWork : NSArray = result.valueForKey("work") as! NSArray
self.worklabel.text = "\(userWork)"
print(userWork)
// Convert String to NSDate
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-yyy"
let date = dateFormatter.dateFromString(userBirthday as String)
let birthday: NSDate = date!
var now: NSDate = NSDate()
var ageComponents: NSDateComponents = NSCalendar.currentCalendar().components(.Year, fromDate: birthday, toDate: now, options: [])
var age: Int = ageComponents.year
// Request profile picture
let strPictureURL: String = (result.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as? String)!
self.namelabel.text = "\(userName), \(age)"
self.image.image = UIImage(data: NSData(contentsOfURL: NSURL(string: strPictureURL)!)!)
}
})
}