Search code examples
iosswiftparse-platformmbprogresshud

Swift: Extra Argument "progressblock" in call


I'm having problems realising exactly why I am getting the error quoted in the question title when trying to implement a progress timer on my block.

func uploadImage(imageData: NSData!) {

    let imageFile = PFFile(name: "\(PFUser.currentUser().username)'s Avatar", data: imageData)

    // Show the HUD to prompt user of upload
    hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
    hud.mode = MBProgressHUDModeDeterminateHorizontalBar
    hud.labelText = "Changing Image..."

    // Upload the image
    imageFile.saveInBackgroundWithBlock({ (succeeded: Bool, error: NSError!) -> Void in

        // Check there was no error, begin handling the file upload
        // trimmed out un-necessary code

        }, progressBlock: { (amountDone: Int32) -> Void in
            self.hud.progress = amountDone/100 as Float
    })
}

If I remove the line self.hud.progress = amountDone/100 as Float everything works as I'd expect, however putting anything within the progressBlock causes my application to crash.

I'm following a Parse tutorial for uploading images, only difference is I am working with Swift so I am needing to convert from Objective-C, however I can't see why this would make a huge difference in the syntax for constructing the second block.


Solution

  • It is casting issue.

    You need to cast amountDone variable in to Float or CGFloat from Int32.

    var flotAmount = Float(amountDone)
    

    Check type of self.hud.progress if it is Float than use

    self.hud.progress = Float(flotAmount/100)
    

    And if it is CGFloat then use below line:

    self.hud.progress = CGFloat(flotAmount/100)