0

I have a very large set of images to upload, and the best way to do that is to let my app do it for me. But after copy and pasting the code from Parse's docs, it doesn't work.

var image = NSData(contentsOfURL: NSURL(string: "XY1_EN_1.jpg")!)!
@IBAction func xyButton1(sender: AnyObject) {

    for var i = 1; i < 147; i++ {

        let imageData = UIImageJPEGRepresentation(image)
//ERROR on line above: Missing argument for parameter #2 in call

        let imageFile = PFFile(name:"image.png", data:imageData)

        var userPhoto = PFObject(className:"Cards")
        userPhoto["imageName"] = "XY1_EN_1"
        userPhoto["imageFile"] = imageFile
        userPhoto.save()    
    }
}

What am I doing wrong?

4
  • did you simply forget the ", 0.5" there?? stackoverflow.com/a/25294325/294884 Commented May 15, 2015 at 1:52
  • I might be mistaken, but wouldn't this just upload the exact same image 146 times? Commented May 15, 2015 at 1:54
  • When I add the 0.5, I get an error: "Cannot invoke 'UIImageJPEGRepresentation' with an argument list of type '(NSData, Double)'" Commented May 15, 2015 at 1:57
  • @Dare Yes, you're right, I haven't finished the coding yet. Thanks for the advice though! Commented May 15, 2015 at 1:59

1 Answer 1

1

There are two problems with the code. UIImageJPEGRepresentation(::) takes two parameters, a UIImage and a float. Right now you are calling UIImageJPEGRepresentation(_:) and giving it NSData. If you want to use that method to get NSData from an Image, you need to make self.image of UIImage type instead of NSData. Maybe init your variable image with UIImage(named: "imageName") if the image is bundled.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.