我有一个单例类:
final class NotificationSingleton : NSObject {
static let sharedInstance = NotificationSingleton()
var aProperty: String!
var anotherProperty: Int!
}
如何确保 aProperty
和 anotherProperty
只能通过 sharedInstance
访问?
最佳答案
您可以将初始化程序设为私有(private) 因此不能创建其他实例
private override init() {}
关于ios - 确保单例属性无法通过其他实例访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35817225/