2012-08-16 14 views
0

我想使一個類別採用協議,我有一個問題,看起來像一個簡單的事情。iOS錯誤:「協議限定符沒有」ID「是古老的」當在一個類別中使用協議

接口聲明:

@interface UIView (UIViewCategory) <DesiredProtocol> 

而且我是假設的實現聲明應該是相同的:

@implementation UIView (UIViewCategory) <DesiredProtocol> 

不過這樣會在XCode中黃色的警告,與消息:「協議沒有'id'的限定符是古老的「。

所以應該聲明是:

@implementation UIView (UIViewCategory) id<DesiredProtocol> 

我找不到這個特定問題的參考。非常感謝所有答覆。

回答

2

你不需要上的協議列表@implementation塊,不管它是否是一個類。

@implementation UIView (UIViewCategory) 
... 
@end 
+0

+1對。它在'@ implementation'中被忽略,就像普通的'@interface' +'@ implementation'對一樣 – justin 2012-08-16 17:42:07

0

這是你如何定義一個協議

@protocol ProtocolName <NSObject> 

//protocol methods 

@end 

後來它的屬性

@interface ProtocolClass: NSObject 
{...} 
@end 
@property (nonatomic, unsafe_unretained) id <ProtocolName> delegate; 
//Synthesize it! 

然後你通過它

@interface ClassThatAdoptsProtocol: NSObject <ProtocolName>{...}