Created
January 20, 2018 07:06
-
-
Save jackyshan/7a084291a03ae55815631697be1ae995 to your computer and use it in GitHub Desktop.
写个简单的Swift检测Controller没有销毁的工具
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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