I am making a class for sharing. This class will be used many times in my project. So I have defined many methods there with a parameter that specify refrence UIViewcontroller on which i want to present something like SLComposeViewController
. I just want to ask one thing that is it normal to pass a UIVIewcontroller as parameter or it is not recommended to pass UIVIewController as parameter.
// ViewController Class
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func shareFacebook(sender: UIButton) {
let sharePanelObj = SharePanel()
sharePanelObj.facebookShare(self)
}
@IBAction func shareTwitter(sender: UIButton) {
}
}
// Reusable Base Class
class SharePanel: NSObject {
func facebookShare (refrenceViewController:UIViewController) -> () {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
let fbShare:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
refrenceViewController.presentViewController(fbShare, animated: true, completion: nil)
} else {
let alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
refrenceViewController.presentViewController(alert, animated: true, completion: nil)
}
}
}