我收到了这个错误:

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

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

所以我综合了自己。

这是协议(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协议(protocol)继承了BGIhaveNavigationController协议(protocol)

我可以通过添加以下警告来删除该警告:
-(UINavigationController *) navigationController
{
    return self.navigationController;
}

但这是荒谬的。在某种意义上
-(UINavigationController *) navigationController
    {
        return self.navigationController;
    }

uit_code已通过UINavigationController存在

最佳答案


@dynamic navigationController;

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

如果您尝试自己实现它,最终将导致重复存储(因此事情可能无法按预期工作)或递归。

关于objective-c - 自动属性综合即使已实现,也不会合成协议(protocol)中声明的属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16977640/

10-15 15:29
查看更多