Skip to content

Commit

Permalink
폴더 네이밍 변경
Browse files Browse the repository at this point in the history
폴더 네이밍 변경
  • Loading branch information
pkh0225 committed Dec 30, 2024
1 parent 6a85e33 commit 229dcbd
Show file tree
Hide file tree
Showing 41 changed files with 398 additions and 96 deletions.
29 changes: 26 additions & 3 deletions Example-iOS/TestSwiftHelper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
200019CB2C9D0B9D00E2094A /* MemoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 200019CA2C9D0B9D00E2094A /* MemoryViewController.swift */; };
200019CF2C9D2CAC00E2094A /* ScopeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 200019CE2C9D2CAC00E2094A /* ScopeViewController.swift */; };
200EB4BD2CEDC0BD0011BD7B /* SwiftHelper in Frameworks */ = {isa = PBXBuildFile; productRef = 200EB4BC2CEDC0BD0011BD7B /* SwiftHelper */; };
2058367A2D226AD50069323D /* DeinitChecker in Frameworks */ = {isa = PBXBuildFile; productRef = 205836792D226AD50069323D /* DeinitChecker */; };
520F389721229A890081B956 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520F389621229A890081B956 /* AppDelegate.swift */; };
520F389921229A890081B956 /* TestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520F389821229A890081B956 /* TestViewController.swift */; };
520F389C21229A890081B956 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 520F389A21229A890081B956 /* Main.storyboard */; };
Expand Down Expand Up @@ -39,6 +40,7 @@
buildActionMask = 2147483647;
files = (
200EB4BD2CEDC0BD0011BD7B /* SwiftHelper in Frameworks */,
2058367A2D226AD50069323D /* DeinitChecker in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -112,6 +114,7 @@
name = TestSwiftHelper;
packageProductDependencies = (
200EB4BC2CEDC0BD0011BD7B /* SwiftHelper */,
205836792D226AD50069323D /* DeinitChecker */,
);
productName = Test;
productReference = 520F389321229A890081B956 /* TestSwiftHelper.app */;
Expand All @@ -123,8 +126,9 @@
520F388B21229A890081B956 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 0940;
LastUpgradeCheck = 1410;
LastUpgradeCheck = 1610;
ORGANIZATIONNAME = pkh;
TargetAttributes = {
520F389221229A890081B956 = {
Expand All @@ -144,6 +148,7 @@
mainGroup = 520F388A21229A890081B956;
packageReferences = (
200EB4BB2CEDC0BD0011BD7B /* XCLocalSwiftPackageReference "../../SwiftHelper" */,
205836782D226AAA0069323D /* XCRemoteSwiftPackageReference "DeinitChecker" */,
);
productRefGroup = 520F389421229A890081B956 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -241,6 +246,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -304,6 +310,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down Expand Up @@ -343,7 +350,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 6.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
_EXPERIMENTAL_SWIFT_EXPLICIT_MODULES = YES;
};
Expand All @@ -368,7 +375,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 6.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
_EXPERIMENTAL_SWIFT_EXPLICIT_MODULES = YES;
};
Expand Down Expand Up @@ -404,11 +411,27 @@
};
/* End XCLocalSwiftPackageReference section */

/* Begin XCRemoteSwiftPackageReference section */
205836782D226AAA0069323D /* XCRemoteSwiftPackageReference "DeinitChecker" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pkh0225/DeinitChecker.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
200EB4BC2CEDC0BD0011BD7B /* SwiftHelper */ = {
isa = XCSwiftPackageProductDependency;
productName = SwiftHelper;
};
205836792D226AD50069323D /* DeinitChecker */ = {
isa = XCSwiftPackageProductDependency;
package = 205836782D226AAA0069323D /* XCRemoteSwiftPackageReference "DeinitChecker" */;
productName = DeinitChecker;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 520F388B21229A890081B956 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"originHash" : "c758d8ff8a6484d5f674fde26eb2e2bddd9121edce77812365795e9d4bfaa225",
"pins" : [
{
"identity" : "deinitchecker",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pkh0225/DeinitChecker.git",
"state" : {
"revision" : "25d2d09b67d48dbc43f632820b9a22ab2b26db28",
"version" : "1.0.0"
}
}
],
"version" : 3
}
4 changes: 2 additions & 2 deletions Example-iOS/TestSwiftHelper/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import SwiftHelper

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -15,8 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIViewController.swizzleMethodForDealloc()
UIView.enableBorderLayerSwizzling()
// UIView.enableBorderLayerSwizzling()
return true
}

Expand Down
118 changes: 90 additions & 28 deletions Example-iOS/TestSwiftHelper/VC/MemoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,46 @@

import UIKit
import SwiftHelper
import DeinitChecker

class MemoryViewController: UIViewController, RouterProtocol {
class MemoryViewController: UIViewController, RouterProtocol, DeinitChecker {
var deinitNotifier: DeinitNotifier?

static var storyboardName: String = ""

class AAA {
class AAA: DeinitChecker {
var deinitNotifier: DeinitNotifier?

var bbb: BBB?

deinit {
print("\(#function) \(Self.self)")
init () {
setDeinitNotifier()
}
}
class BBB {
class BBB: DeinitChecker {
var deinitNotifier: DeinitNotifier?

var array = [WeakWrapper<AAA>]()
// var array = [AAA]()

deinit {
print("\(#function) \(Self.self)")
init () {
setDeinitNotifier()
}
}

var testDataa: AAA?

var test2VC: Test2ViewController!

override func viewDidLoad() {
super.viewDidLoad()
self.title = "Memory"
self.view.backgroundColor = .white
DeinitManager.shared.isRun = true

setDeinitNotifier()

let btn = TestButton(frame: CGRect(x: 100, y: 100, width: 100, height: 100)).apply { obj in
obj.setTitle("click", for: .normal)
let btn = TestButton(frame: CGRect(x: 100, y: 100, width: 200, height: 100)).apply { [weak self] obj in
guard let self else { return }
obj.setTitle("WeakWrapper test", for: .normal)
obj.backgroundColor = .green
obj.addAction(for: .touchUpInside) { [weak self] btn in
guard let self else { return }
Expand All @@ -56,33 +64,87 @@ class MemoryViewController: UIViewController, RouterProtocol {


self.testDataa = a


let v = TestView(frame: CGRect(x: 10, y: 210, w: 250, h: 100))
v.backgroundColor = .red
self.view.addSubview(v)

let btn2 = TestButton(frame: v.bounds).apply {
$0.setTitle("push New ViewController", for: .normal)
$0.addAction(for: .touchUpInside) { _ in
Self.pushViewController()
// print(self)
// print(v)
}
}
v.addSubview(btn2)

test2VC = Test2ViewController()
self.addChild(test2VC)
self.view.addSubview(test2VC.view)
test2VC.view.frame = CGRect(x: 100, y: 350, width: 200, height: 100)

}

// override func viewWillDisappear(_ animated: Bool) {
// super.viewWillDisappear(animated)
//
// if self.isMovingFromParent {
// print("------- is being popped")
// // 여기서 pop 이벤트 처리
//
//
// }
// }
}

extension UIViewController {
private struct AssociatedKeys {
nonisolated(unsafe) static var deallocator: UInt8 = 0
class Test2ViewController: UIViewController, DeinitChecker {
var deinitNotifier: DeinitNotifier?

override func viewDidLoad() {
super.viewDidLoad()
setDeinitNotifier()
view.backgroundColor = .blue

let button = TestButton()
button.frame = self.view.bounds
button.autoresizingMask = [.flexibleWidth, .flexibleHeight]
button.setTitle("Test2ViewController", for: .normal)
button.addAction(for: .touchUpInside) { _ in
alert(title: "", message: "Test2ViewController")
// print(self)
}
view.addSubview(button)
}
}

class TestButton: UIButton, DeinitChecker {
var deinitNotifier: DeinitNotifier?

class func swizzleMethodForDealloc() {
let originalSelector = #selector(viewDidLoad)
let swizzledSelector = #selector(swizzled_viewDidLoad)
guard
let originalMethod = class_getInstanceMethod(Self.self, originalSelector),
let swizzledMethod = class_getInstanceMethod(Self.self, swizzledSelector)
else { return }
method_exchangeImplementations(originalMethod, swizzledMethod)
override init(frame: CGRect) {
super.init(frame: frame)
setDeinitNotifier()
}

@objc private func swizzled_viewDidLoad() {
let deallocator = Deallocator { print("swizzled deinit: \(Self.self)") }
objc_setAssociatedObject(self, &AssociatedKeys.deallocator, deallocator, .OBJC_ASSOCIATION_RETAIN)
required init?(coder: NSCoder) {
super.init(coder: coder)
setDeinitNotifier()
}
}

class TestView: UIView , DeinitChecker {
var deinitNotifier: DeinitNotifier?

override init(frame: CGRect) {
super.init(frame: frame)
setDeinitNotifier()
}

class TestButton: UIButton {
deinit {
print("\(#function) \(Self.self)")
required init?(coder: NSCoder) {
super.init(coder: coder)
setDeinitNotifier()
}
}


2 changes: 1 addition & 1 deletion Sources/SwiftHelper/ETC/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

@MainActor
public func makeDebugTextView(value: String) {
guard let window = KeyWindow() else { return }
guard let window = keyWindow() else { return }
let bgView: UIView = UIView(frame: window.bounds)
bgView.backgroundColor = .black.withAlphaComponent(0.3)
window.addSubview(bgView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ public final class Queue<T> {
return value
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

@MainActor
@inline(__always) public func KeyWindow() -> UIWindow? {
public func keyWindow() -> UIWindow? {
if #available(iOS 13.0, *) {
let scenes = UIApplication.shared.connectedScenes.first as? UIWindowScene
return scenes?.windows.first
Expand All @@ -20,8 +20,8 @@ import UIKit
}

@MainActor
@inline(__always) public func MainNavigation() -> UINavigationController? {
guard let navigationController = KeyWindow()?.rootViewController as? UINavigationController else { return nil }
public func MainNavigation() -> UINavigationController? {
guard let navigationController = keyWindow()?.rootViewController as? UINavigationController else { return nil }
return navigationController
}

Expand Down Expand Up @@ -59,7 +59,7 @@ public protocol RouterProtocol: UIViewController {
public extension RouterProtocol {
static var storyboardName: String { return "" }
static func isAllowSameVCPush() -> Bool {
return false
return true
}

// MARK:- assembleModule
Expand Down Expand Up @@ -122,3 +122,21 @@ public extension RouterProtocol {
navi.visibleViewController?.present(vc, animated: animated, completion: completion)
}
}

extension UIViewController {
private struct AssociatedKeys {
nonisolated(unsafe) static var cache: UInt8 = 0
}

public var cache: Bool {
get {
if let info: Bool = objc_getAssociatedObject(self, &AssociatedKeys.cache) as? Bool {
return info
}
return false
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.cache, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
Loading

0 comments on commit 229dcbd

Please sign in to comment.