在 Xcode 6 中不导入 UIKit.h 就无法访问 UIImage 类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26285381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot access UIImage class without importing UIKit.h in Xcode 6?
提问by luna_
#import <Foundation/Foundation.h>
@interface FaceObject : NSObject
@property (strong, nonatomic) UIImage *image;
@end
Xcode gives an error saying "unknown type name 'UIImage' unless I import UIKit.h, but in Xcode 5 i would have not gotten this error and did not need to import UIKit -- is there any explanation for this? Am I doing something wrong? Thanks!
Xcode 给出一个错误,说“未知类型名称‘UIImage’,除非我导入 UIKit.h,但在 Xcode 5 中我不会得到这个错误并且不需要导入 UIKit——对此有任何解释吗?我在做什么吗?错了?谢谢!
采纳答案by ryanipete
Xcode 6 no longer includes a .pch file by default. In previous versions, that file included the UIKit import (more info here - Why isn't ProjectName-Prefix.pch created automatically in Xcode 6?).
默认情况下,Xcode 6 不再包含 .pch 文件。在以前的版本中,该文件包含 UIKit 导入(更多信息在这里 -为什么 ProjectName-Prefix.pch 不在 Xcode 6 中自动创建?)。
回答by Ronaldoh1
In 2015 -- still getting this error. I always forget to include
在 2015 年 - 仍然收到此错误。我总是忘记包括
#import <UIKit/UIKit.h>
That should take care of it.
那应该照顾它。