programcode
programcode

Reputation: 102

No type or protocol named 'ComposeDelegate' error after adding bridging header

XCode 12.1

This project target gets compiler errors after an umbrella header is added add swift functionality to an existing objective c target

Now there is an error of No type or protocol named 'ComposeDelegate' on all of the target's existing various <ComposeDelegate> declarations.

ComposeViewController.h

@class ComposeViewController;
@class DataModel;
@class Message;

// The delegate protocol for the Compose screen
@protocol ComposeDelegate <NSObject>
- (void)didSaveMessage:(Message*)message atIndex:(int)index;
@end

// The Compose screen lets the user write a new message
@interface ComposeViewController : UIViewController /*<UITextViewDelegate>*/

@property (nonatomic, assign) id<ComposeDelegate> delegate;
@property (nonatomic, strong) DataModel* dataModel;
@property (nonatomic, strong) AFHTTPClient *client;
@end

enter image description here

Other similar code errors appear elsewhere in the target's code as well.

enter image description here

enter image description here

How can this be fixed?

Upvotes: 0

Views: 899

Answers (1)

Ol Sen
Ol Sen

Reputation: 3368

create a file for your protocol and copy the protocol declaration into that.

// ComposeDelegate.h

#idndef ComposeDelegate_h
#define ComposeDelegate_h

// The delegate protocol for the Compose screen
@protocol ComposeDelegate <NSObject>
- (void)didSaveMessage:(Message*)message atIndex:(int)index;
@end

#endif

then use this file to include where ever you want. While creating an extra file may seem extra work, it gives you more control of the pre-processing of your source.

The macro #ifndef SomeName_h ... #endif keeps the code from being implemented twice.

PS: If you code a @interface and the declared Class is not used earlier/above you don't have to and should not pre-declare the ClassName (@class ComposeDelegate;) if not really needed.

Upvotes: 1

Related Questions