Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. @IBOutlet weak var comment: UITextField!
  2. @IBOutlet weak var imageToPost: UIImageView!
  3.  
  4. @IBAction func postImage(_ sender: Any) {
  5. if let image = imageToPost.image {
  6.  
  7. // Create the class object for the Post
  8. let post = PFObject(className: "Post")
  9. post["Message"] = comment.text
  10. post["userId"] = PFUser.current()?.objectId
  11.  
  12. // Create the image data
  13. if let imageData = image.pngData() {
  14. let imageFile = PFFileObject(name: "image.png", data: imageData)
  15. post["imageFile"] = imageFile
  16. post.saveInBackground { (success, error) in
  17. if let error = error {
  18. print("There were issues saving the file: (error.localizedDescription)")
  19. self.displayAlert(title: "Error", message: "Image could not be posted, please try again later")
  20. } else {
  21. // SAving successful
  22. print("File saved correctly")
  23. self.displayAlert(title: "Image Posted", message: "Your image hase posted successfully")
  24. self.comment.text = ""
  25. self.imageToPost.image = nil
  26. }
  27. }
  28. }
  29.  
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement