xcode 如何处理`使用未声明的标识符'UIDevice'`

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35507457/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:33:41  来源:igfitidea点击:

How to deal with `Use of undeclared identifier 'UIDevice'`

iosxcodeuikituidevice

提问by Creator

I followed the MD file step by step. But there is still an error in the compilation. What can I do?

我是按照MD文件一步一步来的。但是编译还是有错误。我能做什么?

In the FaceppClient.m file :

在 FaceppClient.m 文件中:

if ([[[UIDevice currentDevice] systemVersion] compare: @"5.0" options: NSNumericSearch ] != NSOrderedAscending)
    _ios50orNewer = true;

Xcode outputs this error :

Xcode 输出此错误:

Use of undeclared identifier 'UIDevice'

使用未声明的标识符“UIDevice”

I added #import "UIDevice.h"in the file, but Xcode outputs "UIDevice.h not found".

#import "UIDevice.h"在文件中添加,但 Xcode 输出"UIDevice.h not found".

I added the UIKitframework to the Project, but I still have the compilation issue.

我将UIKit框架添加到项目中,但仍然存在编译问题。

What can I do then?

那我能做什么?

回答by Micha?l Azevedo

Try adding this line at the top of your .m file :

尝试在 .m 文件的顶部添加这一行:

#import <UIKit/UIKit.h>

Adding the framework to the project is useful, but you also have to include the needed headers in your code.

将框架添加到项目中很有用,但您还必须在代码中包含所需的头文件。

回答by Peter Brockmann

And for Swift 5 users who got here, try

对于来到这里的 Swift 5 用户,请尝试

import UIKit