为什么编译器看不到@synthesize和@dynamic?
这不是新代码。在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里的行是
@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.意味着有一个名为 filename 的属性,其 getter 名为“iFileName”。
并且该属性确实没有合成,
我猜您想要做的是将 iFileName 的 getter 名称定义为“fileName”,即:
通过 Synthesize 为属性 iFileName 生成一个名为 fileName 的 getter
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 :
which makes a getter named fileName for the property iFileName by synthesize
使用
@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.
我通过将使用 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.