ios Swift - “使用未解析的标识符”

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

Swift - "use of unresolved identifier"

iosxcodeswiftswift2xib

提问by Artem Tutov

I am studying Swift! I want create Main interface on xib. But have error "use of unresolved identifier".

我正在学习斯威夫特!我想在 xib 上创建主界面。但是有错误“使用未解析的标识符”。

enter image description here

在此处输入图片说明

Add code from MainViewController

添加代码来自 MainViewController

import Foundation

public class MainViewController : BaseViewController {

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        // TODO: Write your test code here
        // ...
    } }

UPD:(Add image) enter image description here

UPD:(添加图片) 在此处输入图片说明

回答by Breek

1) Right Click your MainViewController.swift

1)右键单击您的 MainViewController.swift

2) Select Show File Inspector

2) 选择 Show File Inspector

3) On Right side panel, look at Target Membership

3) 在右侧面板上,查看 Target Membership

4) Add your class to target by check the box :)

4)通过选中该框将您的课程添加到目标:)

回答by Divyansh Jain

This same issue happened with me too. I've only one target membership and still, I was getting “use of unresolved identifier”. I build the project and nothing changed.

同样的问题也发生在我身上。我只有一个目标成员资格,但仍然“使用未解析的标识符”。我构建了这个项目,没有任何改变。

I tried to uncheck and recheck the target membership and the issue was resolved.

我尝试取消选中并重新选中目标成员资格,问题已解决。

If this doesn't resolve your issue, try building the project, check for typo error or use autocompletion and Quick Help to find recognized identifiers.

如果这不能解决您的问题,请尝试构建项目,检查拼写错误或使用自动完成和快速帮助来查找可识别的标识符。

回答by Mike

You likely didn't add the class to the target. Click on the MainViewControllerclass and open the utilitiestab on the upper right corner in Xcode:

您可能没有将该类添加到目标中。单击MainViewController类并在 Xcode 中打开右上角的实用程序选项卡:

enter image description here

在此处输入图片说明

Make sure the appropriate target is checked.

确保选中了适当的目标。

EDIT: Apparently you don't have target membership there - which is bizarre in and of itself. Try re-creating the MainViewControllerclass from scratch and make sure the correct target is selected:

编辑:显然你在那里没有目标会员 - 这本身就很奇怪。尝试MainViewController从头开始重新创建类并确保选择了正确的目标:

enter image description here

在此处输入图片说明

回答by 0xa6a

Just a tip for those who found this question with this issue like mine.

只是给那些像我一样发现这个问题的人的提示。

This issue tortured me for days! I can run the project but the red error sign kept showing up. At first blamed this to Xcode (Sorry, Xcode).

这个问题折磨了我好几天!我可以运行该项目,但红色错误标志一直显示。起初将此归咎于 Xcode(对不起,Xcode)。

But after I read all the answers in this thread and checked my source file's Target Membership, I realized that I was wrong to blame Xcode.

但是在我阅读了这个线程中的所有答案并检查了我的源文件之后Target Membership,我意识到责怪 Xcode 是错误的。

The file where this issue was reported had three Target Membership: the main one, the one for tests and another for ui tests. But the variable it refer to was in a file that had only one Target Membership, the main one.

报告此问题的文件有三个Target Membership:主要文件,用于测试的文件和用于 ui 测试的文件。但是它引用的变量在一个只有一个Target Membership,主要的文件中。

So to recap: check the Target Membershipof the file where issue is reported, and of the one where the unresolved identifieris declared. Make sure Membershipthe later contains that of the formal.

所以回顾一下:检查Target Membership报告问题的文件的文件,以及unresolved identifier声明问题的文件。确保Membership后者包含正式的内容。