The iOS Action Extension sample code does not seem to work.
In xCode, I create a new Swift project and choose Single View Application.
Then I se
There's a bug in the Swift version of Xcode's project template for this kind of extension, apparently because of an error when someone was converting from Objective-C to Swift.
To make a long story short: the line that reads "found = true" is in the wrong place. This causes the method doneWithResults
to be called twice when it should only be called once. On the first call it sets self.extensionContext = nil
. On the second call it tries to use self.extensionContext
and throws an exception due to unwrapping a nil optional. But the exception message gets swallowed by the extension system, so there are no clues.
If you change this code in the project template:
itemProvider.loadItemForTypeIdentifier(String(kUTTypePropertyList), options: nil, completionHandler: { (item, error) in
let dictionary = item as! [String: AnyObject]
NSOperationQueue.mainQueue().addOperationWithBlock {
self.itemLoadCompletedWithPreprocessingResults(dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as! [NSObject: AnyObject])
}
found = true
})
to look like this:
itemProvider.loadItemForTypeIdentifier(String(kUTTypePropertyList), options: nil, completionHandler: { (item, error) in
let dictionary = item as! [String: AnyObject]
NSOperationQueue.mainQueue().addOperationWithBlock {
self.itemLoadCompletedWithPreprocessingResults(dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as! [NSObject: AnyObject])
}
})
found = true
...then it works as expected.
I filed the bug rdar://22482042
about this and I encourage you to file one as well.