SHARE
TWEET

Untitled

a guest Jul 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top