I had this in the viewDidLoad of my ProfileViewController
self.user = Auth.auth().currentUser
self.databaseRef.child("user_profiles").child(self.user!.uid).observeSingleEvent(of: .value) { (snapshot:DataSnapshot) in
let snapshotValue = snapshot.value as? NSDictionary
if(snapshotValue?["about"] != nil)
{
}
if(snapshotValue?["profile_pic"] != nil)
{
let databaseProfilePic = snapshotValue!["profile_pic"]
as! String
let data = try? Data(contentsOf: URL(string: databaseProfilePic)!)
self.setProfilePicture(imageView: self.profilePic,imageToSet: UIImage (data:(data!))!)
}
with also this function
internal func setProfilePicture(imageView:UIImageView,imageToSet:UIImage)
{
imageView.layer.cornerRadius = 22.5
imageView.layer.borderColor = UIColor.white.cgColor
imageView.layer.masksToBounds = true
imageView.image = imageToSet
}
to load the profile picture of the authenticated users. My only problem is that every time i go into my ProfileViewController it takes 3-4 seconds to load the picture while i would like that as on instagram, whatsapp etc. the image is already loaded, so there is no such annoying waiting time. How can i do?