I have implemented one UIButton-derived class (RoundButton) in Swift and the rest is still in Objective-C. How do I access both Objective-C-based classes and Swift-based cla
I wanted to add two other solutions that worked for me, in two separate cases were I got the same message (Unknown class MySwiftClass in Interface Builder file.
)
In the first case, I had a Swift subclass of a UIViewController. Well I had thought I wanted to set something in init so I had implemented:
override func initWithNibName:bundle:
As that's the designated initializer... I was every doing anything in the method yet, it was just in place. And yet at runtime my class was not seen until I removed that method.
The other case I had a different Swift UIViewController
subclass that also was not being found at runtime. The end fix for that was to re-name the Swift class (I added a "2" into the name). I changed the class also in the storyboard, and suddenly it worked... this was after trying to remove the name from the storyboard and re-adding, which did not work.
Both of these cases may really be other examples of the accepted answer - but in my case just changing the name in the storyboard was not enough, I had to change the swift class itself in some way.
You should make sure that you have added Objective C bridging header. It is not a problem to use both Objective C and Swift in the same storyboard.
http://i58.tinypic.com/33aqbyu.png
It seems that Xcode 6.0 (6A215l) needs to upgrade the Storyboard file to a newer version before it can access Swift classes.
If you replaced an Objective-C class with a Swift class with the same name, you need to open the Storyboard, edit the name of the custom class (like remove the last letter), save the Storyboard and then rename the class back. This will force the Storyboard file to be upgraded to a newer version, and the new Xcode to correctly write the custom class key like this:
Version information diff:
UIButton custom class definition diff:
After these changes in the Storyboard file the warning seems to disappear and the correct custom class is used.
It indeed seems like an issue with the Storyboard file itself in Xcode 6.0 (6A254o) / iOS 8 Beta 3.
If you're using pre-Xcode 6 Storyboard version it might help to manually update the subclass that Interface Builder is complaining about simply by forcing update of the 'Custom Class' field in the 'Identity Inspector'.