创建单例类
class Manager: NSObject {
static let manager = Manager()
static func shared() -> Manager {
//返回同一个对象
return manager
}
static var name: String!
}
ViewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
Manager.shared().name = "Zhangsan"
print(Manager.name)
//1. UIApplication
//单例类: 只有一个对象
let app = UIApplication.sharedApplication()
let us = NSUserDefaults.standardUserDefaults()
//程序局部性
let fileManager = NSFileManager.defaultManager()
}
找Window的三个方法:
let window = UIApplication.sharedApplication().keyWindow
let window = UIApplication.sharedApplication.delegate?.window
let window = self.view.window