19

Today extension doesn't show up in a Swift app, but it does in a Objective C app.

What I did was to add a UILabel with some content on the storyboard for the swift and objective c apps.

It showed up when I ran the Objective C app, but not when I executed the Swift app.

Am I missing something here?

esh
  • 2,742
  • 5
  • 20
  • 37

4 Answers4

26

You can comment out the supplied init method.

//    init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
//        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
//        // Custom initialization
//    }

This will allow your extension to run properly. The issue seems to be caused by differing initializer behavior between Swift and Objective-C. Removing the above initializer will inherit all of the required initializers from the superclass.

Found that solution on the apple developer forums for your reference.

Note: You may have to Clean and Build your project after doing this before the changes will have any effect

The extension is actually crashing, with an error like:

fatal error: use of unimplemented initializer 'init(coder:)' for class 'com_blabla_blabla_MyTodayExtension.TodayViewController'

This indicates that another option would be to implement:

init(coder aDecoder: NSCoder!) {
    super.init(coder: aDecoder)
    // Custom initialization here
}

if you want to retain the ability to do custom initialization.

Andrew
  • 15,074
  • 6
  • 61
  • 100
  • 1
    This is a very important answer. Lots of people having trouble using Swift to make widgets for iOS 8, and this quick-fix does the trick. – n00neimp0rtant Jun 18 '14 at 14:35
  • 3
    @n00neimp0rtant This is also covered [here](http://stackoverflow.com/a/24036440/2446155) – Andrew Jun 18 '14 at 14:37
3

An app extension target must include the arm64 (iOS) or x86_64 architecture (OS X) in its Architectures build settings.

See Apple's documentation

Erkan Ateşli
  • 87
  • 2
  • 8
  • Thank you! This definitely solves my problem. Apparently Xcode doesn't include the appropriate 64-bit architecture automatically, as stated in the documentation. Everyting worked fine in the simulator, but on my device (5s) the widget's body wouldn't appear. – Pim Oct 17 '14 at 13:41
2

Xcode6 is beta and this is a bug with it, you will have to wait for a new release.

Kris Gellci
  • 8,943
  • 5
  • 35
  • 47
  • Are you sure, because I didn't find this in the release notes. So this means , I won't be able to work with extensions with Swift right now? – esh Jun 06 '14 at 05:49
  • 2
    Im pretty sure its a bug, a lot of people have run into it, you will just have to wait for the next beta update, it is beta software after all! – Kris Gellci Jun 06 '14 at 05:51
1

The problem for me was that the extension's deployment target was set to a different version than my app's target. You should confirm the extension's target is set appropriately because it may target a different version.

enter image description here

Oren
  • 4,905
  • 3
  • 31
  • 51