Protocols implementation in AppDelegate.m: "the prefix attribute must be followed by an interface or protocol"

I am adding two protocols to the AppDelegate so that I can change the controllers of the root view. I did this in a previous project (2 months ago) and it worked fine:

@interface AppDelegate () <ChangeRootController1, ChangeRootController2>

@end

      

So, I did the same in today's project, but then all my functions are throwing this error:

There is no context for method declaration

So I tried this:

@interface AppDelegate () AppDelegate <ChangeRootController1, ChangeRootController2>

@end

      

And now I get

Prefix attribute must be followed by an interface or protocol

      

What's the correct way to get AppDelegate.m to conform to the protocols?

+3


source to share


2 answers


Your first snippet is correct - there is nothing wrong with that:

@interface AppDelegate () <ChangeRootController1, ChangeRootController2>

@end

      



I think the error is misleading you. Did you force you to put your method declarations (for example from these protocols) between @implementation AppDelegate

and @end

?

+2


source


Forget about the second block of code you added there. The first one is correct!

What is missing is that you have some methods (maybe the ones that are required ChangeRootController1

ChangeRootController2

) outside of your implementation block. Method definitions should always be inside the implementation block of the owner class.



@interface AppDelegate () AppDelegate <ChangeRootController1, ChangeRootController2>

@end

@implementation AppDelegate

//methods go here

@end

      

+1


source







All Articles