在tableview控制器中访问AppDelegate函数?

时间:2015-12-03 15:51:55

标签: swift uiviewcontroller appdelegate uiapplicationdelegate uiapplication

我们正在使用Swift,我们在项目文件夹中创建了一个“UITableViewController”。我们正在尝试访问我们的“AppDelegate”功能。我们尝试过使用

    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 

我们也试过

    let appDelegate = UIApplication.sharedApplication()

为什么这不起作用?

我们也有

    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

在我们的“ViewController”中,它可以在那里工作。

错误是“使用未声明的类型'AppDelegate'”

1 个答案:

答案 0 :(得分:0)

将该行更改为

let appDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext