I had the same requirement but could not work out how to override the _shouldExcludeActivityType
method in swift either.
After some failed experimenting with method swizzling I came to the conclusion that using Objective-C to create the derived class and then using a bridging header to expose the derived class to the rest of my swift code was the simplest and best approach.
If you really want to implement most of the logic in swift just get the overridden _shouldExcludeActivityType
method in the Objective-C derived class to delegate to some method that returns a BOOL and then create another derived class in swift that overrides that method.
Object-C Derived Class Header
#import <UIKit/UIKit.h>
@interface BaseBrowserActivityViewController : UIActivityViewController
- (BOOL)shouldExcludeActivityType:(UIActivity *)activity;
@end
Object-C Derived Class Implementation
#import "BaseBrowserActivityViewController.h"
@interface BaseBrowserActivityViewController ()
@end
@implementation BaseBrowserActivityViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)_shouldExcludeActivityType:(UIActivity *)activity
{
return [self shouldExcludeActivityType:activity];
}
- (BOOL)shouldExcludeActivityType:(UIActivity *)activity
{
assert(false); // shouldExcludeActivityType requires overriding.
return false;
}
@end
Swift Derived Class Implementation
import UIKit
class BrowserActivityViewController: BaseBrowserActivityViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func shouldExcludeActivityType(_ activity: UIActivity!) -> Bool {
// Do some testing of the activity here.
return true
}
}