I just upgraded from swift 2 to swift 3 and I am running into some problems with overriding a property.
In swift 2 you could set the activity type like this
override func activityType() -> String? {
return "com.a.string"
}
However in swift 3 (in Xcode 8 beta 6) they introduced NS_STRING_ENUM and now we override activityType like this
override var activityType() -> UIActivityType? {
return UIActivityType.customActivityType
}
The problem is that Xcode will complain with this: Property cannot be an @objc override because its type cannot be represented in Objective-C
One solution i found is to add the annotation @nonobjc to it like so:
@nonobjc override var activityType() -> UIActivityType? {
return UIActivityType.customActivityType
}
While this helps make the error go away, this property never gets called... This is a problem because when the user completes the activity and completionWithItemsHandler() gets called, the activity type is considered nil.
One work around I found is to use an objective-c extension. It works; it gives me type "horse" like I wanted.
@interface Custom_UIActivity (custom)
- (UIActivityType)activityType;
@end
@implementation Custom_UIActivity (custom)
- (UIActivityType)activityType {
return @"horses";
}
My question is how to do it in a pure swift.
In pure Swift3 I am able to compile it using
override var activityType: UIActivityType {
return UIActivityType(rawValue: self.customActivityType.rawValue)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With