Unknown Class **** in Interface Builder file
Asked Answered
C

13

17

I added a UIView xib file using the root class of MyView.

I created it in the wrong place and so moved it in the project. Same project just a different folder/group.

I then had a problem when running saying...

Unknown Class MyView in Interface Builder file

I couldn't work out what was wrong so I have now deleted the files both from the project and from the directory.

I've done a search using SublimeText2 for the string "MyView" and it doesn't exist anywhere in the project.

I've reset the simulator, cleaned the project and the build folder and deleted derived data.

Still getting the same error.

Any ideas what I can do now?

Coherence answered 16/10, 2013 at 11:6 Comment(5)
did u check ur .m file in the compile sources?Nickey
Make sure you've imported the header in the right place. Try adding the import elsewhere and see if it works. Files owner should be the place.Holierthanthou
There is no file to import. I deleted it. How can I check the compile source?Coherence
Target->Build Phases->Compile sourcesNickey
I checked there but it isn't mentioned. Just restarted my computer. Still nothing.Coherence
P
25

Sometimes IBuilder missed customModule="AppName" customModuleProvider="target"

To fix it, open storyboard as source code and replace this line:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass"
sceneMemberID="viewController">

to this:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass"
 customModule="AppName" customModuleProvider="target" sceneMemberID="viewController">
Parthenon answered 30/11, 2014 at 16:10 Comment(3)
All the other fixes didn't work for me, but this did. customModuleProvider was missing for me. Wow that was annoying. This pushes me even closer to just building all my interfaces programatically.Macromolecule
Thank you, this fixed it for me too!!!! After hours of trying other things .... smhPlacida
This wasn't exactly my problem. For me, a few lines down from where you referenced, there was an extraneous "customClass" tag............::: <view key="view" contentMode="scaleToFill" id="someID" customClass="myClass"> .........to........: <view key="view" contentMode="scaleToFill" id="someID">Staffman
A
14

In my case, I solved by checking "Inherit Module From Target" option in Identity Inspector. enter image description here

Ambulatory answered 26/3, 2019 at 13:29 Comment(1)
Worked for me, thnxSabina
F
9

Go to View -> Utilities Goto File Inspector of .m file

Open the Target Membership section and make sure that your target is selected for this .m-file

Fluorocarbon answered 19/1, 2015 at 7:50 Comment(0)
R
6

If you have multiple targets in your Xcode project, make sure that the class the was mentioned in the error file is compiled for the target you're testing with as well.

Rausch answered 1/12, 2014 at 9:37 Comment(1)
Yes, exactly, I've tried like a gazillion solutions but this is the only one that actually worked. I didn't have the build target "ticked" in class itself. Thank you, sir!Endways
D
3

appcode is very stubborn in keeping the old xib cached somewhere, and if you have the cached xib and it has the same name that your controller it will try to load it on start.

what I do after deleting a .xib:

  1. delete app from the device
  2. clean build folder in app code
  3. invalidate caches and restart, kill appcode before it starts
  4. delete derived data in xcode
  5. start appcode

step 4 shouldn't be necessary, but my feeling is that without it I am still seeing the deleted .xib

Digitigrade answered 14/3, 2014 at 11:4 Comment(0)
M
2

This happened to me when I renamed the custom view class, and the module (in the identity inspector when the view is selected) was blank. It remained blank because Xcode didn't autocomplete the custom class name, hence it left the module blank. All I had to do was re-enter the class name after a build, and then it autocompleted, and selected to appropriate module (Current - Target)

enter image description here

Moores answered 24/8, 2016 at 16:26 Comment(0)
C
1

OK, so I deleted all references to the class causing the problem but still nothing.

However, I also had a UIViewController subclass called MyViewController. This wasn't being loaded in any IB file so I don't know how it was causing the problem.

I changed the name to MyOtherViewController.

Build - Run - works.

I don't know how or why but it works now.

Coherence answered 16/10, 2013 at 12:6 Comment(0)
B
1

I had the same issue when I had multiple class declarations in one file. What I did is I declared a UITableViewCell subclass in one of my view controllers, and forgot to put the UITableViewCell subclass' @implementation in the view controller's .m file.

Bac answered 28/5, 2014 at 18:13 Comment(0)
E
0

As my experience, All solutions above had not worked out. Then I had to re-input the custom class in all strayed Xibs. As an amazing result, it just succeeded and what I had done reconnected the lost connection between @interface and IB. Hope to be useful.

Erotica answered 11/7, 2016 at 8:25 Comment(0)
B
0

I encountered this problem when using a custom class from a SPM packet. Setting the Custom Class Module to the SPM Packet name solved the issue for me.

enter image description here

Brockington answered 31/3, 2021 at 6:59 Comment(0)
M
0

In my case it was that the class implementation was enclosed into #ifdef but the #ifdef condition had a typo, so the class really was missing

Masturbate answered 8/6, 2022 at 12:54 Comment(0)
H
0

I encountered the same problem when viewcontroller class was not part of the same target, make the target option checked for that viewcontroller, clean, build and run the project

enter image description here

Hightension answered 8/8, 2022 at 11:26 Comment(0)
K
0

Also worked for me to find the file with unknown class in project if you have many xibs and storyboards. I just used this terminal command

cd MY_PROJECT_PATH
find . -type f \( -name "*.xib" -o -name "*.storyboard" \) -exec grep -l "MY_UNKNOWN_CLASS_NAME" {} +

just replace MY_PROJECT_PATH with path to your project and MY_UNKNOWN_CLASS_NAME with the class name you see in warning message

Karrah answered 20/2 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.