类型参数不能应用于非 class 类型 'id'

Type arguments cannot be applied to non-class type 'id'

我是 ObjectiveC 的新手,已经在 Swift 工作了几年。因此,我不明白 Xcode 中以下解释的错误:

Type arguments cannot be applied to non-class type 'id'

我的协议:

@protocol ExampleProtocol<NSObject>
@required
        
-(NSString *)title;
-(NSString *)album;
    
@end

我在 MyService.h 文件中的实现:

@interface MyService : NSObject 
@property (nonatomic, assign, readwrite) id<ExampleProtocol> delegate;
@end

错误发生在行:

> @property (nonatomic, assign, readwrite) id<ExampleProtocol> delegate;

另外:

也尝试过:

任何建议都会有所帮助。我想了解为什么会这样。我的项目中还有许多其他协议是用 ObjectiveC 编写的,它们工作正常。

ExampleProtocol 是协议,而不是 class。如果导入 header,则不需要它。如果你不导入 header,它应该是 @protocol ExampleProtocol;