venerdì 23 giugno 2017

Fix the issue "Unknown class xxx in Interface Builder file"

Trying to mix Objective C and Swift class I faced the followed issue: running my application and opening a specific View Controller (written in objective C) using a table cell (written in Swift) including a custom view (written in Swift) I saw the following message in the XCode 9 console:

"Unknown class MTMCheckbox in Interface Builder file"

The 3 involved class where:

MTMMatchDetailViewController (ObjC)
MTMAvailabilityCell (Swift file + XIB) 
MTMCheckbox (Swift file)

The error comes from MTMAvailabilityCell XIB.

This was the class definition for my MTMCheckbox.swift:


Thanks to this StackOverflow thread and the user1760527's answer I was able to fix adding (MTMCheckbox) after the notation @obj:

This seems a workaround renaming a Swift class: in my case, MTMCheckbox was previously an Objective C class that I rewritten in Swift.

I hope this can help someone else having the same issue.