Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
写个简单的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
You can’t perform that action at this time.