Reputation: 1315
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:
@class ExampleProtocol;
in my MyService.h file at the top.Also tried:
Creating a Swift protocol with @objc
and : class
imported over the app-Bridging.h gives me the same result with the same error message.
Clean build
Clean build folder (removed derived data)
The only thing that did work was to remove the line from the public interface to the private. This doesn't make sense. I wan't to set the delegate from another class and creating a public setter which set the private delegate is ugly workaround.
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
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