0

I created a protocol

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

// Defines the protocol that must be implemented to be a delegate for UCMapviewController
@protocol UCMapviewDelegate <NSObject>
@required
- (void)pushMapviewRight;

@end

When I go to new file -> protocol, there is a prompt which asks for the target. I check my project. But when i click the protocol.h file in my project and look at file inspector, at "Target membership", my project is unchecked and I cannot check it.

I don't get this error when I put the protocol in the header file of one of my viewControllers (for example). Do I have to import the protocol somewhere else?

WHat is wrong? Help is greatly appreciated! thx

1

1 Answer 1

2

Header files don't go into a target, unless you're building a framework and want to copy the header file into the Headers folder in the framework. When building an app, only source files belong to the target.

You'll notice that if you select one of your other headers in your project, it will also not be in the target. Only the corresponding source file will be. This won't matter. If the header is in your project, you can #import it just fine.

Sign up to request clarification or add additional context in comments.

4 Comments

But if I import the protocol (if so, to the class that conforms to it ??), doesn't that defeat the purpose of it? I mean, my "AppDelegate" does not import UIApplicationDelegate.h ?!
@MJB: UIApplicationDelegate.h is certainly imported by your AppDelegate.m class, by virtue of importing <UIKit/UIKit.h>.
seems like I misunderstood that completely, thanks guys! So I do have to import the protocol.h in every file where I want to "use" it, be it an implementation or delegate property?
@MJB: No. The header for the class that declares conformance to the protocol should #import the protocol header, and now everything that touches that class will get it (since they'll already be #importing your class's header).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.