这两种方法是相同的还是存在重大差异/陷阱需要注意:
class MyClassSingleton {
static let sharedInstance = MyClassSingleton()
private init(){}
func helloClass() { print("hello from class Singleton") }
}
struct MyStructSingleton {
static let sharedInstance = MyStructSingleton()
private init() {}
func helloStruct() { print("hello from struct Singleton") }
}
Run Code Online (Sandbox Code Playgroud) swift ×1