Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue setting CABasicAnimation delegate in Swift 3?

I'm getting the following error

Cannot assign value of type 'StarButton' to type 'CAAnimationDelegate?'

on the last line of this CABasicAnimation block:

 let fillCircle = CABasicAnimation(keyPath: "opacity")
 fillCircle.toValue = 0
 fillCircle.duration = 0.3
 fillCircle.setValue(notFavoriteKey, forKey: starKey)
 fillCircle.delegate = self // this is where the error is thrown

self is a custom UIButton class. This wasn't an issue in previous versions of Swift... any suggestions on a solution?

UPDATE

Here is a downloadable link to the source file for the StarButton class for best reference:

https://www.dropbox.com/s/gvc2sky05f4p3au/StarButton.swift?dl=0

like image 379
Jared Garcia Avatar asked Jul 28 '16 22:07

Jared Garcia


1 Answers

As @Doc mentioned in the comments above, the solution is to replace

class StarButton: UIButton { 

with

class StarButton: UIButton, CAAnimationDelegate {

It would seem that the CAAnimationDelegate protocol is no longer implied and must be specified explicitly.

like image 198
TenaciousJay Avatar answered Oct 28 '22 21:10

TenaciousJay