Skip to content

Instantly share code, notes, and snippets.

@shotastage
Created July 12, 2019 05:22
Show Gist options
  • Save shotastage/ac1454cb5b46663974607e09692b8b06 to your computer and use it in GitHub Desktop.
Save shotastage/ac1454cb5b46663974607e09692b8b06 to your computer and use it in GitHub Desktop.
Singleton + Delegattion
import Foundation
final class StoreObject {
/// Shared Instance
static let shared = StoreObject()
weak var delegate : StoreObjectDelegate?
var value: Int = 0 {
didSet {
self.notifyToDelegate()
}
}
/// Constructor
private init() { }
private func notifyToDelegate() {
self.delegate?.didUpdatedValue()
}
}
/// GeoLocation Service delegate
protocol StoreObjectDelegate: class {
func didUpdatedValue()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment