Swift编译器错误:使用未解析的标识符'name'

时间:2022-12-01 06:30:53

I tried to include a class called 'name' and I got an error:

我试图包含一个名为'name'的类,我收到一个错误:

Swift Compiler Error: Use of unresolved identifier 'name'

The class exists and doesn't contain any compile errors.

该类存在且不包含任何编译错误。

5 个解决方案

#1


60  

There could be a few possible issues.

可能存在一些可能的问题。

  1. One of the classes has a Testing target and other one doesn't. You have to even include all of your classes in the testing target or none of them.

    其中一个类有一个测试目标而另一个没有。您甚至必须在测试目标中包含所有类,或者不包括任何类。

  2. If it's Objective C class, check that the class is in ObjectiveC bridging header file.

    如果是Objective C类,请检查该类是否在ObjectiveC桥接头文件中。

  3. If it's NSManagedObject subclass. Add @objc(className) before the class declaration.

    如果是NSManagedObject的子类。在类声明之前添加@objc(className)。

  4. If it's part of a different framework, make sure that the class or function is public

    如果它是不同框架的一部分,请确保该类或函数是公共的

#2


6  

I had this one too. You will probably find that your first class is included in your testing module and that "name" isn't. Simply, if you include a class in testing, then every class that it references has to be in testing.

我也有这个。您可能会发现您的第一个类包含在您的测试模块中,而“名称”则不包含在您的测试模块中。简单地说,如果在测试中包含一个类,那么它引用的每个类都必须进行测试。

#3


6  

I had this problem too. I was trying to reference Class 1 within the code in Class 2. My problem was that Class 2 had target memberships in A and B, and Class 1 only had Target Memberships in Class A.

我也有这个问题。我试图在Class 2的代码中引用Class 1.我的问题是Class 2在A和B中有目标成员资格,Class 1在A类中只有目标成员资格。

You can fix this by opening the Utilities Tab (farthest right button on the top bar of the Xcode window), and make sure that the same boxes are checked for both classes in the Target Membership subsection.

您可以通过打开“实用工具”选项卡(Xcode窗口顶部栏上最右侧的按钮)来解决此问题,并确保在“目标成员资格”子部分中检查两个类的相同框。

#4


1  

Got problem solved by

解决了问题

Target -> Build Phases -> Compile Sources -> Adding the class file

目标 - >构建阶段 - >编译源 - >添加类文件

#5


-1  

Add one more to the list.

再向列表中添加一个。

  1. If it is part of another framework, make certain that the "Build Active Architecture Only" settings are the same.
  2. 如果它是另一个框架的一部分,请确保“仅构建活动体系结构”设置是相同的。

#1


60  

There could be a few possible issues.

可能存在一些可能的问题。

  1. One of the classes has a Testing target and other one doesn't. You have to even include all of your classes in the testing target or none of them.

    其中一个类有一个测试目标而另一个没有。您甚至必须在测试目标中包含所有类,或者不包括任何类。

  2. If it's Objective C class, check that the class is in ObjectiveC bridging header file.

    如果是Objective C类,请检查该类是否在ObjectiveC桥接头文件中。

  3. If it's NSManagedObject subclass. Add @objc(className) before the class declaration.

    如果是NSManagedObject的子类。在类声明之前添加@objc(className)。

  4. If it's part of a different framework, make sure that the class or function is public

    如果它是不同框架的一部分,请确保该类或函数是公共的

#2


6  

I had this one too. You will probably find that your first class is included in your testing module and that "name" isn't. Simply, if you include a class in testing, then every class that it references has to be in testing.

我也有这个。您可能会发现您的第一个类包含在您的测试模块中,而“名称”则不包含在您的测试模块中。简单地说,如果在测试中包含一个类,那么它引用的每个类都必须进行测试。

#3


6  

I had this problem too. I was trying to reference Class 1 within the code in Class 2. My problem was that Class 2 had target memberships in A and B, and Class 1 only had Target Memberships in Class A.

我也有这个问题。我试图在Class 2的代码中引用Class 1.我的问题是Class 2在A和B中有目标成员资格,Class 1在A类中只有目标成员资格。

You can fix this by opening the Utilities Tab (farthest right button on the top bar of the Xcode window), and make sure that the same boxes are checked for both classes in the Target Membership subsection.

您可以通过打开“实用工具”选项卡(Xcode窗口顶部栏上最右侧的按钮)来解决此问题,并确保在“目标成员资格”子部分中检查两个类的相同框。

#4


1  

Got problem solved by

解决了问题

Target -> Build Phases -> Compile Sources -> Adding the class file

目标 - >构建阶段 - >编译源 - >添加类文件

#5


-1  

Add one more to the list.

再向列表中添加一个。

  1. If it is part of another framework, make certain that the "Build Active Architecture Only" settings are the same.
  2. 如果它是另一个框架的一部分,请确保“仅构建活动体系结构”设置是相同的。