0

I'm creating an iOS Audio Unit Extension, based on Apple's FilterDemo example (there is no XCode project template yet). The example project is written in Swift, but I'm trying to replace the its Swift ViewController class with an Objective-C equivalent.

This new Objective-C version of the AUViewController will be instantiated from some Swift code... And it's doing my head in.

The Swift version of the AUViewController is declared like this (snippet from Apple's code):

public class FilterDemoViewController: AUViewController, AUAudioUnitFactory, FilterViewDelegate { 

My interpretation of that is:

@interface FilterDemoViewController : AUViewController <AUAudioUnitFactory, FilterViewDelegate> {

The ViewController is part of a Framework, which will be linked into the Extension.

According to Apple's documentation, AUViewController is a direct subclass of UIViewController.

My problems:

  • In Interface Builder I can't select my custom ViewController class and module; it's not in the list. When I use Apple's Swift version instead it does show up.
  • If I manually add the custom class/module to my IB file (an often suggested fix) the app compiles, but it crashes at runtime when trying to instantiate the ViewController:

2016-04-12 06:19:07.402 PluginProject[9580:4636464] Unknown class _TtC19FilterDemoFramework20FilterDemoViewController in Interface Builder file. Could not cast value of type 'UIViewController' (0x277a538) to 'FilterDemoViewController' (0x12482c).

For reference, this is the crashing code used for the instantiation (again, a snippet from Apple's demo code, which works with Apple's Swift version of the ViewController):

var filterDemoViewController: FilterDemoViewController!
filterDemoViewController = storyboard.instantiateInitialViewController() as! FilterDemoViewController

So it seems like XCode does not recognize my AUViewController subclass as a valid descendant of UIViewController. However, it works flawlessly with the Swift version.

Things I've tried and double-checked:

  • I have added the relevant .h files to my project-bridging-header.h file to enable mixing Objective-C and Swift codebases in my project:

    #import "FilterDemoViewController.h"

  • My source-files all have the correct target memberships

  • The Framework containing the AUViewController is set to 'public'
  • Build Settings->Packaging->Defines Modules is set to Yes
Bram Bos
  • 135
  • 7
  • Can you have a look at [this](http://stackoverflow.com/a/24924967/289501)? If it doesn't help, is it possible to upload a sample project somewhere? – phi Apr 12 '16 at 20:21
  • FYI, there is a template, you need to add a new "Target" to your project (which i believe needs to be a workspace) . There was also a WWDC Video relating to the demo code you mention. – MDB983 Apr 12 '16 at 22:08
  • Ah.. I see the latest XCode update indeed added a template. I guess that will help me solve the issue (or at least figure out a workaround). Thanks! – Bram Bos Apr 13 '16 at 10:00

0 Answers0