xcode 警告“-method”imagePath“未找到(返回类型默认为“id””
你好,我的 iphone 应用程序中有这个奇怪的警告:
-method 'imagePath' not found (return type defaults to 'id'
它在以下行给了我这个警告:
UIImage *image = [UIImage imageNamed:[_occasion imagePath]];
这是我的 Occasion 类标头:
#import <Foundation/Foundation.h>
@interface Occasion : NSObject {
NSString *_title;
NSDate *_date;
NSString *_imagePath;
}
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSDate *date;
@property (nonatomic, retain) NSString *imagePath;
+ (id)occasionWithTitle:(NSString *)title
date:(NSDate *)date
imagePath:(NSString *)imagePath;
- (id)initWithTitle:(NSString *)title
date:(NSDate *)date
imagePath:(NSString *)imagePath;
@end
奇怪的是我仅在 Occasion 的 (imagePath 属性,而其他2 个属性工作正常:
[_occasion date]
我
[_occasion title]
不知道为什么它抱怨找不到该方法,而它是一个属性并且确实存在。
Hi I have this weird warning in my iphone app:
-method 'imagePath' not found (return type defaults to 'id'
It's giving me this warning on the following line:
UIImage *image = [UIImage imageNamed:[_occasion imagePath]];
Here is my Occasion class header:
#import <Foundation/Foundation.h>
@interface Occasion : NSObject {
NSString *_title;
NSDate *_date;
NSString *_imagePath;
}
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSDate *date;
@property (nonatomic, retain) NSString *imagePath;
+ (id)occasionWithTitle:(NSString *)title
date:(NSDate *)date
imagePath:(NSString *)imagePath;
- (id)initWithTitle:(NSString *)title
date:(NSDate *)date
imagePath:(NSString *)imagePath;
@end
The weird thing is I'm getting this warning only on the (imagePath property of Occasion, while the other 2 properties are working fine namely:
[_occasion date]
and
[_occasion title]
I dunno why is it complaining the method is not found while it is a property and it does exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于找到了解决方案。我在 MyFile.m 中导入了 Occasion.h 文件,因为我仅在 MyFile.h 中使用了前向声明 @class Occasion.h。
虽然还是很奇怪
因为 AnotherFile.h 中只有 @class Occasion.h 就足够了,无需在 AnotherFile.m 中导入
I finally found the solution. I imported the Occasion.h file in MyFile.m since I was using the forward declearation @class Occasion.h only in MyFile.h.
It's still weird though
cuz in AnotherFile.h only @class Occasion.h was enough without the import in the AnotherFile.m