I did the following steps:
- Delete the storyboard file from your project
- Modify the info.plist:
Go to the NSExtension Dictionary, remove this key: NSExtensionMainStoryboard. Replace it with this key NSExtensionPrincipalClass and add your ViewController as the value, e.g. TodayViewController.
before:
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widget-extension</string>
</dict>
after:
<key>NSExtension</key>
<dict>
<key>NSExtensionPrincipalClass</key>
<string>TodayViewController</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widget-extension</string>
</dict>
- If you're using Swift, you have to enable "Embedded Content Contains Swift Code" in the Build Settings of the target. Set it to YES.
- Additionally I had to add
@objc (TodayViewController)
in my TodayViewController class (after the imports).
The app should run now. But there were two other things I had to do:
- Create a view. Obviously there is no view created automatically.
So add these lines:
override func loadView()
{
view = UIView(frame:CGRect(x:0.0, y:0, width:320.0, height:200.0))
}
- And set the height of your widget in your viewDidLoad method:
self.preferredContentSize = CGSizeMake(0, 200)