For Swift 4, add as a Delegate to your class:
public protocol TimingDelegate: class {
var _TICK: Date?{ get set }
}
extension TimingDelegate {
var TICK: Date {
_TICK = Date()
return(_TICK)!
}
func TOCK(message: String) {
if (_TICK == nil){
print("Call 'TICK' first!")
}
if (message == ""){
print("\(Date().timeIntervalSince(_TICK!))")
}
else{
print("\(message): \(Date().timeIntervalSince(_TICK!))")
}
}
}
Add to our class:
class MyViewcontroller: UIViewController, TimingDelegate
Then add to your class:
var _TICK: Date?
When you want to time something, start with:
TICK
And end with:
TOCK("Timing the XXX routine")