Question

I'm having a problem when I try to add a second protocol. The first one is working just fine. So I created a test application to try out using two protocols (because I'm still learning how to use protocols). I do not know why I am having so much trouble understanding protocols. I've even gone through tutorials and still struggle with them.

My first issue when I tried to add the second protocol and use it I received the following error:

Assigning to ‘id’ from incompatible type ‘ *const _strong'

But, let's ignore that for now, because my test application is giving me this error for both protocols in my test app:

Cannot find protocol declaration

So, I will post the code for my test application, because I MUST understand the basics before tackling more difficult issues.

DelegateA Header

#import <Foundation/Foundation.h>

@protocol IDDelegateADelegate <NSObject>
@end

@interface IDDelegateA : NSObject
//other properties here
@property (nonatomic, assign) id<IDDelegateADelegate> delegateA;
@end

DelegateA Implementation

#import "IDDelegateA.h"

@implementation IDDelegateA
@synthesize delegateA;
//other methods and properties go here
@end

DelegateB Header

#import <Foundation/Foundation.h>

@protocol IDDelegeteBDelegate <NSObject>
@end

@interface IDDelegeteB : NSObject
//other properties here
@property (nonatomic, assign) id<IDDelegeteBDelegate> delegateB;
@end

DelegateB Implementation

#import "IDDelegeteB.h"

@implementation IDDelegeteB
@synthesize delegateB;
//other methods and properties go here
@end

The test class Header that uses these delegates

#import <Foundation/Foundation.h>
#import "IDDelegateA.h"
#import "IDDelegeteB.h"

@interface IDTestingDelegates : NSObject <IDDelegateA, IDDelegateB>

@end

Right here I receive the Cannot find protocol declaration error for both delegates. I've been searching on SO as well as going through tutorials and sample code. Best answer on SO was here. But I'm just not getting what I'm doing wrong. Can somebody please point out what I am missing here?

Was it helpful?

Solution

@interface IDTestingDelegates : NSObject <IDDelegateA, IDDelegateB>

should be

@interface IDTestingDelegates : NSObject <IDDelegateADelegate, IDDelegeteBDelegate>

You have to list the protocols in <...>, not interfaces.

OTHER TIPS

@interface declares a class, while the ClassName <X> syntax expects X to be a protocol (in your declaration of IDTestingDelegates).

Not sure exactly what you were trying to achieve here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top