Darkwonder
Darkwonder

Reputation: 1315

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

I am new to ObjectiveC and have been working for few years in Swift. Therefore, I don't understand the below explained error in Xcode:

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

My Protocol:

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

My implementation in the MyService.h file:

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

The error occurs in the line:

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

Additionally:

Also tried:

Any suggestion would be helpfull. I would like to understand why this happens. There are a lot of other protocols in my project written in ObjectiveC which work fine.

Upvotes: 0

Views: 3419

Answers (1)

Willeke
Willeke

Reputation: 15623

ExampleProtocol is a protocol, not a class. You don't need it if you import the header. If you don't import the header, it should be @protocol ExampleProtocol;

Upvotes: 3

Related Questions