iosiphoneswiftios8ios-app-extension

Writing an iOS 8 share extension without a storyboard


Does anyone know of a good way to write an iOS 8 share extension without the MainInterface.storyboard that comes with the template?

When I delete the file or remove the NSExtensionMainStoryboard from Info.plist, the extension stops working (nothing happens when you tap on the button in the share pane). We tried replacing NSExtensionMainStoryboard with NSExtensionPrincipalClass which also didn't work.

Any ideas?


Solution

  • Figured it out!

    Turns out there's a weird module naming thing going on in Swift, so you can fix it by adding an @objc name to the class:

    @objc(PrincipalClassName)
    
    class PrincipalClassName: UIViewController {
    ...
    

    and then set the NSExtensionPrincipalClass key to PrincipalClassName.