Skip to content
Snippets Groups Projects
Commit e2ebcdde authored by keleher's avatar keleher
Browse files

auto

parent 89086016
No related branches found
No related tags found
No related merge requests found
//
// VCLLoggingViewController.swift
//
// Created by CS193p Instructor.
// Copyright © 2015-17 Stanford University. All rights reserved.
//
import UIKit
class VCLLoggingViewController : UIViewController
{
private struct LogGlobals {
var prefix = ""
var instanceCounts = [String:Int]()
var lastLogTime = Date()
var indentationInterval: TimeInterval = 1
var indentationString = "__"
}
private static var logGlobals = LogGlobals()
private static func logPrefix(for loggingName: String) -> String {
if logGlobals.lastLogTime.timeIntervalSinceNow < -logGlobals.indentationInterval {
logGlobals.prefix += logGlobals.indentationString
print("")
}
logGlobals.lastLogTime = Date()
return logGlobals.prefix + loggingName
}
private static func bumpInstanceCount(for loggingName: String) -> Int {
logGlobals.instanceCounts[loggingName] = (logGlobals.instanceCounts[loggingName] ?? 0) + 1
return logGlobals.instanceCounts[loggingName]!
}
private var instanceCount: Int!
var vclLoggingName: String {
return String(describing: type(of: self))
}
private func logVCL(_ msg: String) {
if instanceCount == nil {
instanceCount = VCLLoggingViewController.bumpInstanceCount(for: vclLoggingName)
}
print("\(VCLLoggingViewController.logPrefix(for: vclLoggingName))(\(instanceCount!)) \(msg)")
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
logVCL("init(coder:) - created via InterfaceBuilder ")
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
logVCL("init(nibName:bundle:) - create in code")
}
deinit {
logVCL("left the heap")
}
override func awakeFromNib() {
logVCL("awakeFromNib()")
}
override func viewDidLoad() {
super.viewDidLoad()
logVCL("viewDidLoad()")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
logVCL("viewWillAppear(animated = \(animated))")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
logVCL("viewDidAppear(animated = \(animated))")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
logVCL("viewWillDisappear(animated = \(animated))")
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
logVCL("viewDidDisappear(animated = \(animated))")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
logVCL("didReceiveMemoryWarning()")
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
logVCL("viewWillLayoutSubviews() bounds.size = \(view.bounds.size)")
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
logVCL("viewDidLayoutSubviews() bounds.size = \(view.bounds.size)")
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
logVCL("viewWillTransition(to: \(size), with: coordinator)")
coordinator.animate(alongsideTransition: { (context: UIViewControllerTransitionCoordinatorContext!) -> Void in
self.logVCL("begin animate(alongsideTransition:completion:)")
}, completion: { context -> Void in
self.logVCL("end animate(alongsideTransition:completion:)")
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment