An advanced Ethereum/EVM mobile wallet
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.
 
 
 
alpha-wallet-ios/Trust/Foundation/Subscribable.swift

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)
}
}