我在嘗試添加第二個協議時出現問題。第一個工作正常。所以我創建了一個測試應用程序來嘗試使用兩種協議(因爲我仍然在學習如何使用協議)。我不知道爲什麼我在理解協議時遇到了很多麻煩。我甚至通過教程,仍然與他們鬥爭。Objective C協議 - 需要一些愚蠢的基本幫助,請
我的第一個問題,當我試圖添加第二個協議,並使用它,我收到以下錯誤:
Assigning to ‘id’ from incompatible type ‘ *const _strong'
但是,讓我們忽略現在,因爲我的測試應用程序是給我這個錯誤在我的測試應用程序這兩個協議:
Cannot find protocol declaration
所以,我會張貼我的測試應用程序的代碼,因爲我必須解決更多迪之前瞭解的基礎知識困難的問題。
DelegateA部首
#import <Foundation/Foundation.h>
@protocol IDDelegateADelegate <NSObject>
@end
@interface IDDelegateA : NSObject
//other properties here
@property (nonatomic, assign) id<IDDelegateADelegate> delegateA;
@end
DelegateA實施
#import "IDDelegateA.h"
@implementation IDDelegateA
@synthesize delegateA;
//other methods and properties go here
@end
DelegateB部首
#import <Foundation/Foundation.h>
@protocol IDDelegeteBDelegate <NSObject>
@end
@interface IDDelegeteB : NSObject
//other properties here
@property (nonatomic, assign) id<IDDelegeteBDelegate> delegateB;
@end
DelegateB實施
#import "IDDelegeteB.h"
@implementation IDDelegeteB
@synthesize delegateB;
//other methods and properties go here
@end
使用這些代表
#import <Foundation/Foundation.h>
#import "IDDelegateA.h"
#import "IDDelegeteB.h"
@interface IDTestingDelegates : NSObject <IDDelegateA, IDDelegateB>
@end
就在這裏我收到Cannot find protocol declaration
錯誤都代表測試類的頭。我一直在搜索SO以及通過教程和示例代碼。 SO的最佳答案是here。但是我只是沒有明白我做錯了什麼。有人可以指出我在這裏失蹤了什麼嗎?
小寫拼寫錯誤,您在其頭文件和實現中有'IDDelegeteB',但是您在測試類中引用'IDDelegateB' ...在進一步繼續之前更正所有拼寫錯誤是個好主意。 – abiessu
是的,我知道它必須是非常愚蠢的東西。謝謝。 – Patricia