在ios swift中传递'自我'问题

时间:2015-11-28 18:26:42

标签: ios swift

伙计们我在Utility类中编写了一个实用程序函数

func showAlert(vc: UIViewController) {
    if #available(iOS 8.0, *) {
        let alertController = UIAlertController(title: "title", message: "message.", preferredStyle: .Alert)
        let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
        alertController.addAction(defaultAction)

        vc.presentViewController(alertController, animated: true, completion: nil)

    }
}

如果我从currentViewController调用此函数,则会出现类似

的错误

enter image description here

1 个答案:

答案 0 :(得分:2)

AppUtil已经初始化了吗?如果不是,您需要调用AppUtil()或在变量或其他任何内容中初始化它。