How to access both Objective-C and Swift classes from same storyboard?

前端 未结 4 821
一个人的身影
一个人的身影 2020-12-18 09:20

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

4条回答
  •  遥遥无期
    2020-12-18 09:52

    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.

提交回复
热议问题