设计模式 - twototwoto/WYW_Blog GitHub Wiki
# 单例设计模式
/* 单例实现 */
class Singleton {
static let sharedInstance = Singleton()
private init() {}
}
extension Singleton : NSCopying, NSMutableCopying {
func copy(with zone: NSZone? = nil) -> Any {
return Singleton.sharedInstance
}
func mutableCopy(with zone: NSZone? = nil) -> Any {
return Singleton.sharedInstance
}
}
// 单例访问方式
Singleton.sharedInstance
参考学习内容
- Swift 开发者必备 Tips
- Design Patterns by Tutorials