5

我得到了那个错误:

/business/Dropbox/badgers/BadgerNew/BGProfileView.m:56:17: Auto property synthesis will not synthesize property declared in a protocol

我知道自动属性合成不会合成协议中声明的属性

所以我综合了我的自我。

这是协议:

@protocol BGIhaveNavigationController <NSObject>

@property (readonly)UINavigationController * navigationController;//This is the problematic property

@end

@protocol BGCommonProtocol <NSObject>


@end

至于执行

@interface BGProfileView : UIViewController

@end

是一个 UIViewController 并且我们知道 UIViewController 有一个 navigationController 属性。那么有什么问题呢?

当我使用它时,事情会出现问题:

@interface BGProfileView () <BGReviewsTableDelegateProtocol>

BGReviewsTableDelegateProtocol 协议继承 BGIhaveNavigationController 协议

我可以通过添加删除警告:

-(UINavigationController *) navigationController
{
    return self.navigationController;
}

但这是荒谬的。从某种意义上说

-(UINavigationController *) navigationController
    {
        return self.navigationController;
    }

-(UINavigationController *) navigationController已经通过 UINavigationController 存在

4

1 回答 1

10

利用

@dynamic navigationController;

这告诉编译器属性实现在“其他地方”,并且它应该相信该要求将在运行时得到满足。实际上,这意味着它在超类中。

如果您尝试自己实现它,您最终会得到重复存储(因此事情可能不会按您的预期工作)或递归。

于 2013-06-07T07:02:04.427 回答