ios - 无法解析协议(protocol)中的类型
<p><pre><code>#import "MPOContactAuthorizationManager.h"
@protocol MPOContactAuthorizationManagerDelegate <NSObject>
- (void)authorizationManger:(MPOContactAuthorizationManager *)manager
didUpdateContactState:(ContactsState)contactState;
@end
</code></pre>
<p><code>MPOContactAuthorizationManager</code> 和 <code>ContactState</code> 不解析为类型,即使它们在 MPOContactAuthorizationManager 中声明:</p>
<pre><code>#import "MPOContactAuthorizationManagerDelegate.h"
typedef enum _contactsState {
kContactsStateUnknown,
kContactsStateAllowed,
kContactsStateDisallowed
} ContactsState;
@interface MPOContactAuthorizationManager : NSObject <UIAlertViewDelegate> {
ContactsState _contactsAuthorizationState;;
}
@property (strong, nonatomic) NSObject<MPOContactAuthorizationManagerDelegate> *delegate;
@property (nonatomic) ContactsState contactsAuthorizationState;
</code></pre>
<p>关于为什么这些没有解决的任何想法?两者都收到错误“预期类型”</p>
<p>谢谢
迈克</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你有一个循环依赖。通过删除 <code>#import</code> 行并添加以下内容来更新 <code>MPOContactAuthorizationManagerDelegate.h</code>header :</p>
<pre><code>@class MPOContactAuthorizationManager;
</code></pre>
<p>就在 <code>@protocol</code> 行之前。</p>
<p>只需将两者放在一个 .h 文件中(您仍然需要 <code>MPOContactAuthorizationManager</code> 的前向声明):</p>
<pre><code>typedef enum _contactsState {
kContactsStateUnknown,
kContactsStateAllowed,
kContactsStateDisallowed
} ContactsState;
@class MPOContactAuthorizationManager;
@protocol MPOContactAuthorizationManagerDelegate <NSObject>
- (void)authorizationManger:(MPOContactAuthorizationManager *)manager
didUpdateContactState:(ContactsState)contactState;
@end
@interface MPOContactAuthorizationManager : NSObject <UIAlertViewDelegate> {
ContactsState _contactsAuthorizationState;;
}
@property (strong, nonatomic) NSObject<MPOContactAuthorizationManagerDelegate> *delegate;
@property (nonatomic) ContactsState contactsAuthorizationState;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 无法解析协议(protocol)中的类型,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18603379/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18603379/
</a>
</p>
页:
[1]