Skip to content

Instantly share code, notes, and snippets.

@jackyshan
Created January 20, 2018 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackyshan/7a084291a03ae55815631697be1ae995 to your computer and use it in GitHub Desktop.
Save jackyshan/7a084291a03ae55815631697be1ae995 to your computer and use it in GitHub Desktop.
写个简单的Swift检测Controller没有销毁的工具
//
// CheckWselfHelper.swift
// alliance
//
// Created by jackyshan on 2018/1/19.
// Copyright © 2018年 GCI. All rights reserved.
//
import Foundation
class CheckWselfHelper {
static let shared = CheckWselfHelper()
private var vcs = [String]()
func pushVc(_ vc: UIViewController) {
#if DEBUG
if vc is JYTabBarViewController {
return
}
vcs.append(NSStringFromClass(vc.classForCoder))
#endif
}
func popVc(_ vc: UIViewController?) {
#if DEBUG
guard let vc = vc else {return}
let str = NSStringFromClass(vc.classForCoder)
vcs = vcs.filter({$0 != str})
var datas = [String: Int]()
vcs.forEach({ (str) in
datas[str] = (datas[str] ?? 0)+1
})
datas.forEach({ (key, value) in
if value > 1 {
Log.i("注意"+key+"没有释放")
}
})
#endif
}
func clearVcs(_ addVc: UIViewController?) {
#if DEBUG
vcs.removeAll()
guard let addVc = addVc else {return}
pushVc(addVc)
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment