我正在制作一个共享类。这个类将在我的项目中被多次使用。因此,我在其中定义了许多方法,其中有一个参数指定了要呈现的视图控制器的引用,例如SLComposeViewController
。我只想问一件事,那就是将UIVIewController作为参数传递是否正常,或者不建议将UIVIewController作为参数传递。
// 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)
}
}
}