是否有人可以請建議或指導,我如何返回在Location 1
處獲得的ProfileImage
,並將其返回到Location 2
。將不勝感激您的幫助。我已經去了其他的SO問題,但沒有一個幫助我。我如何從完成處理程序中獲取一個值iOS Swift 3
static var profileImage : UIImage{
get{
let defaults = UserDefaults.standard
guard let imageData = defaults.object(forKey: "profileImage") as? NSData else{
downloadAndSetProfileImage(completionHandler: { (profileImage) in
// LOCATION 1:
// PLEASE ADVISE HOW I CAN RETURN THE OBTAINED PROFILE IMAGE BELOW at LOCATION 2
})
}
// LOCATION 2:
// I would like to return the profileImage Here i.e. return profileImage
}
set (image){
let defaults = UserDefaults.standard
let imageData : NSData = UIImagePNGRepresentation(image)! as NSData
defaults.set(imageData, forKey: "profileImage")
}
}