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.

3
  • CAAnimationDelegate is declared in QuartzCore framework, #import <QuartzCore/QuartzCore.h>. Commented Aug 16, 2016 at 10:10
  • @KudoCC I have tried but it does't work,Thanks. Commented Aug 16, 2016 at 10:29
  • this may help have a look Commented Aug 16, 2016 at 10:54

2 Answers 2

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 
Sign up to request clarification or add additional context in comments.

3 Comments

Even with this conditional you might have trouble debugging in iOS 9.
When you try and print a variable value using iOS 9, LLDB will complain that it cannot compile the header file containing CAAnimationDelegate.
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.
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.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.