宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
//  LD_Def.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/28.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import Foundation
// MARK: -- Function
///当前的VC
public func LD_currentViewController() -> UIViewController {
    var currVC:UIViewController?
    var Rootvc = UIApplication.shared.keyWindow?.rootViewController
    repeat {
        if (Rootvc?.isKind(of: NSClassFromString("UINavigationController")!))! {
            let nav = Rootvc as! UINavigationController
            let v = nav.viewControllers.last
            currVC = v
            Rootvc = v?.presentedViewController
            continue
        }else if (Rootvc?.isKind(of: NSClassFromString("UITabBarController")!))!{
            let tabVC = Rootvc as! UITabBarController
            currVC = tabVC
            Rootvc = tabVC.viewControllers?[tabVC.selectedIndex]
            continue
        }else {
            return currVC!
        }
 
    } while Rootvc != nil
    return currVC!
}
 
///当前的NavVC
public func LD_currentNavigationController() -> UINavigationController {
    return LD_currentViewController().navigationController!
}
 
//MARK: - 加载xib视图
public protocol LDNibView{}
 
public extension LDNibView where Self : UIView{
 
    @discardableResult
    ///加载方式不同:用于非pod项目中,加载xib所使用
    public static func ld_loadNibView() -> Self {
        return Bundle.main.loadNibNamed(Mirror(reflecting: self).description.replacingOccurrences(of: "Mirror for", with: "").replacingOccurrences(of: ".Type", with: "").trimmingCharacters(in: CharacterSet.whitespaces), owner: nil, options: nil)?.first as! Self
    }
}
 
class TapButton:UIButton{
    
}
 
final class Box<T> {
        // 声明一个别名
    typealias Listener = (T) -> Void
    var listener: Listener?
 
    var value: T? {
        didSet {
            guard let v = value else { return }
            listener?(v)
        }
    }
 
    init(_ value: T? = nil){
        self.value = value
    }
 
    func bind(listener: Listener?) {
        self.listener = listener
        guard let v = value else { return }
        listener?(v)
    }
}