gpt4 book ai didi

objective-c - 自动属性合成不会合成协议(protocol)中声明的属性,即使它已实现

转载 作者:太空狗 更新时间:2023-10-30 03:48:57 25 4
gpt4 key购买 nike

我得到了那个错误:

/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;
}

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

最佳答案

使用

@dynamic navigationController;

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com