Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Counter<V> : CustomDebugStringConvertible {
- private var _value: V
- private(set) var valueReadCount = 0
- private(set) var valueWriteCount = 0
- init(value: V) {
- self._value = value
- }
- mutating func reset() {
- valueReadCount = 0
- valueWriteCount = 0
- }
- var debugDescription: String {
- return ("\(_value) is read \(valueReadCount) times and written \(valueWriteCount) times")
- }
- var val : V {
- mutating get {
- valueReadCount += 1
- return _value
- }
- set {
- valueWriteCount += 1
- _value = newValue
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement