我目前正在尝试将变量从应用程序委托转移到ViewController。我发现的大多数指南都在Objective-C中,而且我不具备将代码转换为快速代码的技能。有人可以帮我找到解决方法。
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
var isIpad: Bool!
if UIDevice.current.userInterfaceIdiom == .pad {
isIpad = true
print("iPad")
}else{
print("not iPad")
isIpad = false
}
}
答案 0 :(得分:-1)
尽管我建议您看一看@rmaddy的第一条评论,但是您可以在模块中的任何位置声明一个存储属性(不必在应用程序委托中声明):< / p>
let isIpad = UIDevice.current.userInterfaceIdiom == .pad
这意味着不需要将值从应用程序委托传递给视图控制器。因此,在视图控制器中-例如-:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if isIpad {
// ...
}
}
}