我正在使用Swift
和最新的Xcode
版本。
我在AppDelegate.swift
中有此代码:
func testPrint(string: String) {
print(string)
}
我可以像这样从文件ViewController.swift
成功调用该函数:
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.testPrint(string: "Hello!")
但是,如果我尝试从TodayViewController.swift
(适用于苹果Today Extension
)调用该函数,则会出现以下错误:
使用未声明类型的“ AppDelegate”
为什么?
答案 0 :(得分:0)
尝试以下方法:
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.testPrint(string: "Hello!")
编辑: “今日扩展程序”和App处于不同的环境中,因此不可能。