I am using https://github.com/keygx/GradientCircularProgress this cocoa pod to create Gradient Circle in my App
Here is my Code.
import GradientCircularProgress
class MyViewController : UIViewController {
let progress = GradientCircularProgress()
var progressView: UIView?
var Opt2Btn : UIButton?
override func viewDidLoad()
{
super.viewDidLoad()
//My Code
self.create()
}
func reset()
{
self.progressView?.removeFromSuperview()
//self.progressView = nil
// Some more Code
self.create()
}
func create()
{
let ratio: CGFloat = CGFloat(correctCount) / CGFloat(temp.count)
let rect = CGRect(x: 0, y: 0, width: 200, height: 200)
progressView = progress.showAtRatio(frame: rect, display: true, style: GreenLightStyle() as StyleProperty)
progressView?.center = CGPoint(x: self.view.frame.width / 2, y: self.view.frame.width / 2 )
view.addSubview(progressView!)
progress.updateRatio(ratio)
Opt2Btn = UIButton(frame: CGRect(x: 10, y: (progressView?.frame.size.height)! + 190 + (correctLbl?.frame.size.height)! , width: self.view.frame.width - 20 , height: 40))
Opt2Btn?.setTitle("Reset", for: .normal)
Opt2Btn?.backgroundColor = UIColor.blue
Opt2Btn?.layer.borderColor = UIColor .blue.cgColor
Opt2Btn?.addTarget(self, action: #selector(self.reset), for: .touchUpInside)
self.view.addSubview(Opt2Btn!)
}
}
I have tried to produce the same scenario as my App. When I run this code it shows the circle perfectly for the first time. When I hit the button(Opt2Btn) it clears the circle too but not creating again. Gives this error,
fatal error: unexpectedly found nil while unwrapping an Optional value
On view.addSubview(progressView!)
this line. I have tried self.progressView = nil
too but didnt work.
I am new to Swift. Can anyone suggest me what am I doing wrong here? Thank you!!