Rami Ammoun Rami Ammoun - 2 months ago 40
Swift Question

No '+" candidates produce the expected contextual result type 'AnyObject' Error in Swift 3

I have this function that animates a UIImageView:

override func deselectAnimation(_ icon : UIImageView, textLabel : UILabel, defaultTextColor : UIColor) {
playMoveIconAnimation(icon, values:[icon.center.y + 4.0, icon.center.y])
playDeselectLabelAnimation(textLabel)
textLabel.textColor = defaultTextColor

if let iconImage = icon.image {
let renderImage = iconImage.withRenderingMode(.alwaysTemplate)
icon.image = renderImage
icon.tintColor = defaultTextColor
}
}

func playMoveIconAnimation(_ icon : UIImageView, values: [AnyObject]) {

let yPositionAnimation = createAnimation("position.y", values:values, duration:duration / 2)

icon.layer.add(yPositionAnimation, forKey: "yPositionAnimation")
}


After I upgraded to Swift 3 I started receiving the following error:

No '+" candidates produce the expected contextual result type 'AnyObject'


I read in a similar question that the function should have return values but I don't know how to implement this. I would appreciate your help resolving this error

Answer

If you're expecting just values typed as CGFloat change it by:

func playMoveIconAnimation(_ icon : UIImageView, values: [CGFloat]) {

    let yPositionAnimation = createAnimation("position.y", values:values, duration:duration / 2)

    icon.layer.add(yPositionAnimation, forKey: "yPositionAnimation")
}