Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is what you're doing
- upload(image: image!, to: "Users/\(Auth.auth().currentUser!.uid)/photoUrls/0", completion: { urlString, error in
- Database.database().reference().child("Users/\(Auth.auth().currentUser!.uid)/photoUrls/0").setValue(urlString)
- },
- Database.database().reference().child("Users/\(Auth.auth().currentUser!.uid)/photoUrls/0").observeSingleEvent(of: .value) { (snapshot) in
- let urlString = snapshot.value as! String
- let task = URLSession.shared.dataTask(with: URL(string: urlString)!) {(data, response, error) in
- if let image: UIImage = UIImage(data: data!) {
- DispatchQueue.main.async {
- //update the image
- self.ProfileImage.image = image
- }
- }
- }
- task.resume()
- }
- )}
- //This is what you should do:
- //Upload the image
- upload(image: image!, to: "Users/\(Auth.auth().currentUser!.uid)/photoUrls/0", completion: {
- urlString, error in
- Database.database().reference().child("Users/\(Auth.auth().currentUser!.uid)/photoUrls/0").setValue(urlString)
- })
- //Grab the image (it won't be available right away as "upload" is an asynchronous function)
- Database.database().reference().child("Users/\(Auth.auth().currentUser!.uid)/photoUrls/0").observeSingleEvent(of: .value) {
- (snapshot) in
- let urlString = snapshot.value as! String
- let task = URLSession.shared.dataTask(with: URL(string: urlString)!) {
- (data, response, error) in
- if let image: UIImage = UIImage(data: data!) {
- DispatchQueue.main.async {
- //update the image
- self.ProfileImage.image = image
- }
- }
- }
- task.resume()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement