mrackwitz / MRProgress

Collection of iOS drop-in components to visualize progress
MIT License
2.55k stars 305 forks source link

setProgress not working in Swift, docs need updating #133

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi guys,

First off, thanks for putting this really amazing looking library out there

Could someone please provide a solution as to how to implement this beautiful library in Swift

I can load the OverlayView but I can't figure out how to connect the progress

I am using Alamofire

In my post request

var progressFloat: Float = 0.0
...
                    upload.uploadProgress(closure: { //Get Progress
                        progress in

                        print(progress.fractionCompleted)

                       // cast value as float
                       progressFloat = Float(progress.fractionCompleted)

                        // the initial overlay view gets loaded 
                        MRProgressOverlayView.showOverlayAdded(to: self.view, title: "Uploading", mode: MRProgressOverlayViewMode.determinateCircular, animated: true)

                        // this is where I am stuck 
                        // setProgress is a child, but throws error:
//  'use of instance member 'setProgress' on type MRProgressOverlayView'; did you mean to use a value of type MRProgressOverlayView
                        MRProgressOverlayView.setProgress(progressFloat, true)

                      // MRProgressView.setProgress doesn't work either 

I am also getting the error 
/Pods/MRProgress/src/Components/MRProgressOverlayView.m:815
2017-01-23 16:23:32.207 MyProject[5844:139083] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Mode must support setProgress:animated:, but doesnot!'

                        if progress.fractionCompleted == 1 {
                            print("Completed")

                            // this is also throwing an error 
                            MRProgressOverlayView.dismiss(self)
                        }
                    })
ghost commented 7 years ago

Also

http://stackoverflow.com/questions/41808102/how-can-i-implement-mrprogress-in-swift-3

ghost commented 7 years ago

You can add this to the docs for integration with Alamofire 4 and Swift 3

       let overlay = MRProgressOverlayView.showOverlayAdded(to: self.view, title: "Uploading", mode: .determinateCircular, animated: true)

       upload.uploadProgress(closure: { //Get Progress
              progress in

              print(progress.fractionCompleted)

              self.progressFloat = Float(progress.fractionCompleted)

              if progress.fractionCompleted < 1 {

                         overlay?.setProgress(self.progressFloat, animated: true)

              }

              if progress.fractionCompleted == 1 {
                       print("Completed")

                        overlay?.dismiss(true)                                
               }
     })