i have been getting this error fatal error:
unexpectedly found nil while unwrapping an Optional value.
In this code
class ShimmerView: NSObject {
// weak propeties
weak var animatedView : UIView!
// Strong Properties
var shadowBackgroundColor : UIColor!
var shadowForegroundColor : UIColor!
var shadowWidth : CGFloat!
var repeatCount : CGFloat!
var duration : NSTimeInterval!
var currentAnimation : CABasicAnimation!
func commonInit(){
self.shadowBackgroundColor = UIColor(white: 1, alpha: 0.3)
self.shadowForegroundColor = UIColor.whiteColor()
self.shadowWidth = 20
self.repeatCount = CGFloat.infinity
self.duration = 3.0
}
func start(){
if(self.animatedView == nil){
print("ShimmerView has nothing to return")
self.stop()
}
let gradientMask = CAGradientLayer()
gradientMask.frame = self.animatedView.bounds
let gradientSize : CGFloat = self.shadowWidth / self.animatedView.frame.size.width
let startLocations : NSArray = [0,Int(gradientSize / 2.1),Int(gradientSize)]
let endLocations : NSArray = [Int(1.0 - gradientSize) , Int(1.0 - (gradientSize / 2.0)) , 0]
// The error is on this line
gradientMask.colors = [self.shadowBackgroundColor.CGColor , self.shadowForegroundColor.CGColor , self.shadowBackgroundColor.CGColor]
gradientMask.locations = startLocations as? [NSNumber]
gradientMask.startPoint = CGPointMake(0 - (gradientSize * 2), 0.5)
gradientMask.endPoint = CGPointMake(1 + gradientSize, 0.5)
self.animatedView.layer.mask = gradientMask
currentAnimation = CABasicAnimation(keyPath: "locations")
currentAnimation.fromValue = startLocations
currentAnimation.toValue = endLocations
currentAnimation.repeatCount = Float(self.repeatCount)
currentAnimation.duration = self.duration
currentAnimation.delegate = self
gradientMask.addAnimation(currentAnimation, forKey: "ShimmerView")
}
i have debugged but can't really find nothing related to the error i have written in the code where the error occurs