Swift Compiler Error: Use of unresolved identifier 'name'

别说谁变了你拦得住时间么 提交于 2019-11-27 07:34:34

问题


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

Swift Compiler Error: Use of unresolved identifier 'name'

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


回答1:


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.

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

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




回答2:


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:


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.

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.




回答4:


Got problem solved by

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




回答5:


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.


来源:https://stackoverflow.com/questions/26099111/swift-compiler-error-use-of-unresolved-identifier-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!