blockchainethereumblockchain-walleterc20erc721walletxdaidappdecentralizederc1155erc875iosswifttokens
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
626 B
30 lines
626 B
// Copyright SIX DAY LLC. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
open class Subscribable<T> {
|
|
private var _value: T?
|
|
private var _subscribers: [(T?) -> Void] = []
|
|
open var value: T? {
|
|
get {
|
|
return _value
|
|
}
|
|
set {
|
|
_value = newValue
|
|
for f in _subscribers {
|
|
f(value)
|
|
}
|
|
}
|
|
}
|
|
|
|
public init(_ value: T?) {
|
|
_value = value
|
|
}
|
|
|
|
open func subscribe(_ subscribe: @escaping (T?) -> Void) {
|
|
if let value = _value {
|
|
subscribe(value)
|
|
}
|
|
_subscribers.append(subscribe)
|
|
}
|
|
}
|
|
|