ios Swift 编译器错误:使用未解析的标识符“名称”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26099111/
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
Swift Compiler Error: Use of unresolved identifier 'name'
提问by Vojtech Vrbka
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.
该类存在并且不包含任何编译错误。
回答by Vojtech Vrbka
There could be a few possible issues.
可能有几个可能的问题。
One of the classes has a Testing targetand other one doesn't. You have to even include all of your classes in the testing target or none of them.
If it's Objective C class, check that the class is in ObjectiveC bridging header file.
If it's NSManagedObject subclass. Add
@objc(className)
before the class declaration.If it's part of a different framework, make sure that the class or function is
public
其中一个类有一个测试目标,另一个没有。您甚至必须将所有类都包含在测试目标中,或者不包含任何类。
如果是Objective C 类,请检查该类是否在ObjectiveC 桥接头文件中。
如果是 NSManagedObject 子类。
@objc(className)
在类声明之前添加。如果它是不同框架的一部分,请确保类或函数是
public
回答by Owen Godfrey
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.
我也有这个。您可能会发现您的第一个类包含在您的测试模块中,而“名称”却没有。简单地说,如果您在测试中包含一个类,那么它引用的每个类都必须在测试中。
回答by Binya Koatz
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 只有在 Class 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.
您可以通过打开 Utilities 选项卡(Xcode 窗口顶部栏最右侧的按钮)来解决此问题,并确保在 Target Membership 小节中为两个类选中了相同的框。
回答by Bindi
Got problem solved by
问题解决了
Target -> Build Phases -> Compile Sources -> Adding the class file
Target -> Build Phases -> Compile Sources -> 添加类文件
回答by Mark A. Durham
Add one more to the list.
在列表中再添加一个。
- If it is part of another framework, make certain that the "Build Active Architecture Only" settings are the same.
- 如果它是另一个框架的一部分,请确保“仅构建活动架构”设置相同。