Swift 3, beta 6, can't implement UIActivityItemSource

In the Xcode 8 beta 6 compiler, I get a compile error when trying to implement the UIActivityItemSource protocol.


Specifically this optional function...

optional public func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivityType?) -> String

The compiler error is:

"Method cannot be an implementation of an @objc requirement because the type of the parameter 2 cannot be represented in Objective-C."

I've double checked the definition and don't see what I could be doing wrong.

Any ideas?

I have the same problem. In my attempt to find a workaround, I tried marking the method @nonobjc, which enables it to compile, but then it does not get invoked. At this point my iOS 10 development is stuck.

I'm getting the same error when trying to override UIActivity's activityType property, which is of type UIActivityType? Looks like UIActivityType is the culprit in both cases.

Please make sure to file a bug about this. It would also help me if you posted your bug number here.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Bug #27869636

I made a bugreport for the same issue before finding this forum post. My bug # is: 27876753 and includes a sample project if that helps.

You can "change" the parameter from UIActivityType to String and ignore the warnings (for now).


For me it works for beta 6.


I will try again in the next betas.

What do you change to String? I tried (below) but it produces a "Method does not override any method in its superclass" compiler error.


override func activityViewController(_ activityViewController: UIActivityViewController, dataTypeIdentifierForActivityType activityType: String?) -> String {

I have found a work around. You must use an objective-c category to implement that method. So we can keep the swift implementation but minus the method that complains about objc. below is an example but using a different method than the one you mentions. You should be able to apply the same technique.


@interface Custom_UIActivity (custom)

- (UIActivityType)activityType;

@end

@implementation Custom_UIActivity (custom)

- (UIActivityType)activityType {

return @"horses";

}
Swift 3, beta 6, can't implement UIActivityItemSource
 
 
Q