Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBOutlet weak var comment: UITextField!
- @IBOutlet weak var imageToPost: UIImageView!
- @IBAction func postImage(_ sender: Any) {
- if let image = imageToPost.image {
- // Create the class object for the Post
- let post = PFObject(className: "Post")
- post["Message"] = comment.text
- post["userId"] = PFUser.current()?.objectId
- // Create the image data
- if let imageData = image.pngData() {
- let imageFile = PFFileObject(name: "image.png", data: imageData)
- post["imageFile"] = imageFile
- post.saveInBackground { (success, error) in
- if let error = error {
- print("There were issues saving the file: (error.localizedDescription)")
- self.displayAlert(title: "Error", message: "Image could not be posted, please try again later")
- } else {
- // SAving successful
- print("File saved correctly")
- self.displayAlert(title: "Image Posted", message: "Your image hase posted successfully")
- self.comment.text = ""
- self.imageToPost.image = nil
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement