为什么编译器看不到@synthesize和@dynamic?

发布于 2024-11-27 18:53:21 字数 464 浏览 0 评论 0原文

这不是新代码。在 OS 10.7 Lion/LLVM/Clang 之前,它已成功编译和执行数千次。

@interface CapDuring : NSObject {
    const char * iFileName;
...
}
@property(assign) const char * iFileName;
...
@property(readonly,getter=iFileName) const char * fileName;

!属性“fileName”需要定义方法“iFileName” - 使用@synthesize、@dynamic 或提供方法实现

...
@end


@implementation CapDuring
@synthesize iFileName;
...
@end

对于每个类似的声明都会重复此警告(即使使用@dynamic)。

This is NOT new code. It has been compiled and executed successfully thousands of times BEFORE OS 10.7 Lion/LLVM/Clang.

@interface CapDuring : NSObject {
    const char * iFileName;
...
}
@property(assign) const char * iFileName;
...
@property(readonly,getter=iFileName) const char * fileName;

!Property 'fileName' requires method 'iFileName' to be defined - use @synthesize, @dynamic or provide a method implementation

...
@end


@implementation CapDuring
@synthesize iFileName;
...
@end

This warning is repeated for every declaration like it (even if @dynamic is used).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萧瑟寒风 2024-12-04 18:53:21

这里的行是@synthesize iFileName。这是不正确的。您需要@synthesize fileName。您正在综合属性,而不是方法。该方法本身是作为合成属性访问器过程的一部分生成的。

Your line here is @synthesize iFileName. That's incorrect. You want @synthesize fileName. You're synthesizing the property, not the method. The method itself is generated as part of the process of synthesizing the property accessors.

恰似旧人归 2024-12-04 18:53:21
@property(readonly,getter=iFileName) const char * fileName;
@synthesize iFileName;

意味着有一个名为 filename 的属性,其 getter 名为“iFileName”。

并且该属性确实没有合成,

我猜您想要做的是将 iFileName 的 getter 名称定义为“fileName”,即:

@property(readonly,getter=fileName) const char * iFileName;
@synthesize iFileName;

通过 Synthesize 为属性 iFileName 生成一个名为 fileName 的 getter

@property(readonly,getter=iFileName) const char * fileName;
@synthesize iFileName;

means that there's a property called filename that takes its getter as named "iFileName".

and there is really no synthesize for that property

i guess what you want to do is define the getter name of iFileName as "fileName", that's :

@property(readonly,getter=fileName) const char * iFileName;
@synthesize iFileName;

which makes a getter named fileName for the property iFileName by synthesize

§对你不离不弃 2024-12-04 18:53:21

使用
@property(...) ... iInstanceVariable
进而
@property(...,getter=iInstance) ... instanceReference
进入一个单独的@interface(类别)开始给我带来问题。

最好的解决方案是:

@property(...) ... instanceReference;
@synthesize instanceReference = iInstanceVariable;

无论是否在单独的类别中,这都有效。

Using
@property(...) ... iInstanceVariable
and then
@property(...,getter=iInstance) ... instanceReference
into a separate @interface ( category ) began to give me problems.

The best solution is:

@property(...) ... instanceReference;
@synthesize instanceReference = iInstanceVariable;

This works without fail within a separate category or not.

月棠 2024-12-04 18:53:21

我通过将使用 getter 的任何属性(也是属性)移动到单独的 @interface MyClass ( myCompile ) 中来解决此错误。

当通过 getter/setter 重命名操作系统属性/方法时,也会出现同样的问题。

我通过消除操作系统方法的重命名来解决这个问题。

感谢您的所有建议。

I have got around this error by moving any properties which use getters that are also properties into a separate @interface MyClass ( myCompile ).

This same issue arrises when an OS property/method is renamed via a getter/setter.

I got around that by eliminating the renaming of OS methods.

Thank you for all of your suggestions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文