awolf
awolf

Reputation: 1972

Sharing a storyboard across multiple targets in Swift

I've got an app with two targets which have almost identical user interfaces and functionality (pay up front vs. IAPs). For that reason, they share a storyboard. In Objective-C this has been no problem.

However now I'm beginning to implement new view controllers using Swift. The problem I'm having is that I need to specify a "Module" for my custom view controllers implemented in my Storyboard.

The custom view controller's Identity Inspector looks like:

enter image description here

I am forced to designate one of my targets. Whichever target I select, the other target will crash with a message such as:

2017-01-15 17:26:32.284 TapTyping[85802:15083599] Unknown class _TtC13TapTypingLite19EntryViewController in Interface Builder file.

How can I set up my shared Storyboard so that it will build for both targets (as it use to, in Objective-C)?

Upvotes: 2

Views: 2217

Answers (1)

Larry Ricker
Larry Ricker

Reputation: 319

Awolf, I also have a project with multiple targets and I have begun converting it from Objective-C to Swift gradually. Through much testing I found that for the modules that have been extended from Objective-C to Swift as soon as I change the Class from the Objective-C name to the Swift name I also had this error 'Unknown Class XXX in Interface Builder File'. I found through trial and error that the Module has to be specified for the views/tableviews with Swift files or they will not be found. The Module needs to be blank for the views/tableviews with Objective-C files or they will not be found. I did these changes on the raw XML source code by Control-clicking on MainStoryboard.storyboard and choosing Open As, Source Code. My naming convention is that the files converted to swift start with 'ProjectOrganizer' and the modules that are still Objective-C start with 'StatusReport'. Here are two examples:

Objective-C example:img

Swift example:img

After you are done editing the raw XML source you can switch back to the GUI view of Interface Builder by Control-Clicking on the MainStoryBoard.storyboard and selecting Open As, Interface Builder - Storyboard.

If you resolve the Objective - C vs. Swift setting for the Module all the targets will build successfully despite all the Swift files being specified as only one of your targets. Make sure all the custom module settings are set to the same target.

[Swift Example in Interface Builder GUI][3]

[Objective-C Example in Interface Builder GUI][4]

Upvotes: 2

Related Questions