私は fbgraph api から取得し、ビューに表示しています。
フェッチするためのコードは以下のとおりです。
func fetchProfile(){
let parameters = ["fields":"email, name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).startWithCompletionHandler { (connection, result, error) in
if error != nil{
print(error)
return
} else {
print(result)
self.nameLabel.text = result["name"] as? NSString as? String
self.emailAddress.text = result["email"] as? NSString as? String
if let picture = result["picture"] as? NSDictionary, data = picture["data"] as? NSDictionary, url = data["url"] as? String{
print("this is what yout fetch with \(url)")
self.imageView.sd_setImageWithURL(NSURL(string: url))
}
}
}
}
viewDidLoad のコード
override func viewDidLoad() {
super.viewDidLoad()
self.imageView.clipsToBounds = true
self.imageView.layer.masksToBounds = true
self.imageView.layer.cornerRadius = self.imageView.frame.height/2
self.fetchProfile()
}
アプリケーションを実行して表示を開始するたびに、すべてを表示するのに約 1.5 秒かかります。このデータをキャッシュできる方法は他にあります。画面が表示されるたびに、ビューがキャッシュとして表示されると自動的に表示されるため、2.0 秒待つ必要はありません。登場するのは最初のビューなので