Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. struct Counter<V> : CustomDebugStringConvertible {
  2. private var _value: V
  3. private(set) var valueReadCount = 0
  4. private(set) var valueWriteCount = 0
  5.  
  6. init(value: V) {
  7. self._value = value
  8. }
  9.  
  10. mutating func reset() {
  11. valueReadCount = 0
  12. valueWriteCount = 0
  13. }
  14.  
  15. var debugDescription: String {
  16. return ("\(_value) is read \(valueReadCount) times and written \(valueWriteCount) times")
  17. }
  18.  
  19. var val : V {
  20. mutating get {
  21. valueReadCount += 1
  22. return _value
  23. }
  24. set {
  25. valueWriteCount += 1
  26. _value = newValue
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement