6

My code was fine before, but it tips me :

cannot find protocol declaration for 'CAAnimationDelegate';did you mean 'UIApplicationDelegate'?

when I run it today.

I have tried import QuartzCore/CAAnimation.h but doesn't work.

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
Kayle Best
  • 73
  • 1
  • 5

2 Answers2

21

CAAnimationDelegate is a new protocol that was added in the iOS 10 SDK. That means it is there if you build with Xcode 8, but not there if you build with Xcode 7.

When you build with Xcode 8, you'll get a warning to say:

Assigning to 'id<CAAnimationDelegate> _Nullable' from incompatible type 'WhateverUIViewController *const __strong'

If you add the CAAnimationDelegate, your code won't build in Xcode 7 anymore. If you need to build with both Xcode's, you need to use ifdefs:

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 100000
// CAAnimationDelegate is not available before iOS 10 SDK
@interface WhateverUIViewController ()
#else
@interface WhateverUIViewController () <CAAnimationDelegate>
#endif
JosephH
  • 37,173
  • 19
  • 130
  • 154
  • Even with this conditional you might have trouble debugging in iOS 9. – phatmann Sep 16 '16 at 19:07
  • When you try and print a variable value using iOS 9, LLDB will complain that it cannot compile the header file containing CAAnimationDelegate. – phatmann Sep 18 '16 at 17:08
  • For some reason the new documentation lists CAAnimationDelegate as new in iOS 10+. I have apps that go back to iOS 4 that use the delegate methods and old documentation that lists them as from iOS 2. Weird. But then, the new documentation is really badly done. – Paul Linsay Dec 01 '16 at 17:54
4

CAAnimationDelegate is not a protocol. There is no need to tell your class is going to implement the CAAnimationDelegate.

First you need to import QuartzCore/QuartzCore.h.Then, You just pass your class's (in which you want to implement the animation delegate methods) object as delegate to your CAAnimation object. It will automatically calls animationDidStart while starting the animation and calls animationDidStop method while finishing the animation.

BhagyaNivi
  • 741
  • 6
  • 12
  • CAAnimationDelegate became a formal protocol in OS X v10.12, in September 2016, a month after this answer was posted. So anybody reading this answer now should disregard it. – Tommy Mar 22 '20 at 21:37