Replace the import of "MPOContactAuthorizationManagerDelegate.h" from MPContactAuthorizationManager.h by using a forward declaration of the protocol:
@protocol MPOContactAuthorizationManagerDelegate;
typedef enum _contactsState {
kContactsStateUnknown,
kContactsStateAllowed,
kContactsStateDisallowed
} ContactsState;
@interface MPOContactAuthorizationManager : NSObject <UIAlertViewDelegate> {
ContactsState _contactsAuthorizationState;;
}
........
You need to choose this import scheme as you are referring to a user defined type (the ContactsState
type) in the protocol's header - so this header needs to import the manager's header. In the manager's header, however, you only refer to the protocol as the types of the method parameters, so you can legally forward-declare here.
In general, you should only import one header from another in a few cases:
- Declaring a class in your header that's a subclass of a class defined in the other header
- Referring to user defined types (e.g. via a
typedef
) in your header that are defined in the other header
- Declaring a class in your header as conforming to a protocol declared in another header
- Declaring a category in your header for a class defined in another header
- I think I'm forgetting one, so saving this space for that one.
Also - read this enlightening answer.
The more common case of needing protocol and class names in public method parameters and properties can be accomplished using forward declarations with @class
and @protocol
. Although, if it were me, I'd keep the protocol declaration in the same header as the authorization manager - seems more convenient that way. Note that you will need to do a forward-declaration within the file for this. For example:
typedef enum _contactsState {
kContactsStateUnknown,
kContactsStateAllowed,
kContactsStateDisallowed
} ContactsState;
//forward-declare the protocol before referencing it in the file
@protocol MPOContactAuthorizationManager;
@interface MPOContactAuthorizationManager : NSObject <UIAlertViewDelegate> {
ContactsState _contactsAuthorizationState;;
}
@property (strong, nonatomic) NSObject<MPOContactAuthorizationManagerDelegate> *delegate;
@property (nonatomic) ContactsState contactsAuthorizationState;
........
@end
// Provide the real protocol declaration.
@protocol MPOContactAuthorizationManagerDelegate <NSObject>
- (void)authorizationManger:(MPOContactAuthorizationManager *)manager
didUpdateContactState:(ContactsState)contactState;
@end