2

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)?

awolf
  • 1,862
  • 22
  • 29
  • I work the opposite - a few UIViews are in a Framework target and in my apps/extensions my Framework is my module. –  Jan 15 '17 at 23:26
  • Are you sure you have to specify a module? I usually delete the contents of this field and it defaults to `Current - {Module name}`. – Estel Jan 16 '17 at 16:54
  • @dfd yah.. looks like I might need to create a shared Framework for such view controllers – awolf Jan 19 '17 at 13:48
  • @Estel no, Xcode won't let me clear this field (when I change focus it autofills back with "TapTyping" or "TapTypingLite" – awolf Jan 19 '17 at 13:48
  • One bit of caution - I've never tried to *code* a Storyboard, just UIViews. (My storyboards are blank VCs with a background color with everything else in code.) In theory you can code a UIStoryboard(?) inside a framework, but I go one level deeper to UIView instead. You sound like you've set up a Framework target before. If not, here's an answer on how I do things: http://stackoverflow.com/questions/41207622/how-to-make-same-ios-swift-app-with-only-some-differences-in-the-code-and-assets/41209283#41209283 –  Jan 19 '17 at 13:53
  • @dfd Yah, I'm not concerned with getting that to work. I can probably keep the Storyboard in my non-framework / non-shared project since I'm able to specify the specific module the Storyboard should load the view controller from. – awolf Jan 22 '17 at 17:55
  • What a nightmare this is. Sure... creating a shared target is a possible solution, but for my codebase this is a MAJOR migration of almost all the code into a shared target. Would love if there was an easier way. – awolf Jan 22 '17 at 18:51
  • @awolf how do you resolved it? – Santos Ramón Apr 21 '17 at 14:46
  • @SantosRamón I did not resolve it, unfortunately. Instead I reimplemented my 3-4 new Swift view controllers using just code.. no Storyboards. This a pretty big disappointment. This seems to be a really important item that Apple is ignoring. – awolf Apr 30 '17 at 18:16

1 Answers1

2

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]

George
  • 3,384
  • 5
  • 40
  • 64
Larry Ricker
  • 199
  • 1
  • 7
  • If you want to make these changes purely in the Interface Builder GUI, for every Swift View/TableView you need to select a specific (Custom) Module and tick the box for Inherit From Target. For every Objective-C View/TableView leave the (Custom) Module specified as 'None'. – Larry Ricker Jun 04 '17 at 12:54
  • Hi @LarryRicker, your two screenshots appear to be exactly the same. Perhaps a mistake? That aside, what do you specify as the Module for the Swift files? The module is supposed to be the target, but as I stated in the original question, I have two targets. Specifying anything for the Swift files causes the other targets to not build. So I'm not sure your solution would solve that. – awolf Jun 05 '17 at 10:57
  • Thank you for pointing that out. I have 4 screen shots, but restrictions on my ID prevented me from uploading them. I can return later when I get upgraded. I deleted one and uploaded the correct screen shot for Swift. – Larry Ricker Jun 05 '17 at 11:17