Writing an iOS 8 share extension without a storyboard

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.


Instead of the @objc hack, the proper way to do it in Swift is to include the module name in NSExtensionPrincipalClass, i.e.,

<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ActionViewController</string>

(Documenting the error otherwise:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: ...)'

Hopefully will help someone who run into this error in the future.)