Unknown class in interface builder

Max picture Max · Aug 9, 2016 · Viewed 36.2k times · Source

I know that there are a lot of questions on this subject but I've tried most of them to try and figure it out with no success.

the problem: at first I couldn't add my class from the assistant editor cause the custom class didn't pick it up.

  1. I made sure the calls inherits from uiviewcontroller
  2. I made sure the class is added to the target
  3. I tried to remove the class file and re-add it back
  4. finally I've added the class through the storyboard xml and it appeared in the custom class

Now I'm trying to connect my buttons, views etc to its outlets. It seems like they are connected but when running the app and opening that view controller the app crashes and the debugger prints: "Unknown class xxx in Interface Builder file." and than "this class is not key value coding-compliant for the key btnMenu."

I've checked:

  1. That connection inspector is properly set (no error in the outlets there)
  2. Tried to delete derived data
  3. Clean project
  4. Re-install the app

I even tried restarting my mac and of course no success.

can anyone shad some light here? thanks.

Answer

Anthony Scott picture Anthony Scott · Jul 1, 2017

I just had this happen with a UIViewController subclass (with Xcode 9 beta 2 & Swift 4) and the solution was to tick 'Inherit from Target' where I set the Custom Class in IB.

If your view happens to be in a .bundle file (such as for a framework/static library) that gets copied to a different target, you'll want to set an explicit module target for each xib/storyboard class rather than having it inherit from the target that's hosting it.