0

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?

Community
  • 1
  • 1
Patricia
  • 5,019
  • 14
  • 72
  • 152
  • 2
    Minor misspelling, you have `IDDelegeteB` in its header and implementation, but you refer to `IDDelegateB` in the test class... It would be a good idea to correct all misspellings before proceeding further. – abiessu Jan 13 '14 at 18:36
  • Yeah, I knew it had to be something really stupid. Thank you. – Patricia Jan 13 '14 at 18:54

2 Answers2

2
@interface IDTestingDelegates : NSObject <IDDelegateA, IDDelegateB>

should be

@interface IDTestingDelegates : NSObject <IDDelegateADelegate, IDDelegeteBDelegate>

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

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Just before you posted this, I realized my error. Between the misspelling and the wrong protocol declaration, I sure mucked up what should have been an easy test, huh. – Patricia Jan 13 '14 at 18:56
  • Oh, man, I was doing the same thing in the real code. Fixed that and it fixed my first error. Thank you!!!!! :-) – Patricia Jan 13 '14 at 19:04
1

@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.

Taum
  • 2,511
  • 18
  • 18
  • Just a test to try to understand protocols. Now, I'm going to try to use both of these in my test app and see if I can recreate the first issue I was having. Thank you for your help. +1 for you. :-) – Patricia Jan 13 '14 at 18:58
  • Yup, fixed it in the real code and that fixed my first problem. All works fine now. Thanks again. – Patricia Jan 13 '14 at 19:05