Swift Compiler Error: Use of unresolved identifier

2019-01-20 07:09发布

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.

5条回答
Juvenile、少年°
2楼-- · 2019-01-20 07:50

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

查看更多
smile是对你的礼貌
3楼-- · 2019-01-20 07:51

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.
查看更多
来,给爷笑一个
4楼-- · 2019-01-20 08:01

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.

查看更多
神经病院院长
5楼-- · 2019-01-20 08:08

Got problem solved by

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

查看更多
Bombasti
6楼-- · 2019-01-20 08:11

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.

查看更多
登录 后发表回答