Skip to content

Commit

Permalink
Merge pull request #3 from MobileUpLLC/UPUP-692-memory-leak
Browse files Browse the repository at this point in the history
Upup 692 memory leak
  • Loading branch information
reykich authored Dec 2, 2024
2 parents 9f92ad5 + 652cb84 commit 47a0d6e
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 59 deletions.
24 changes: 17 additions & 7 deletions ExampleApp/Example-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict/>
</dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
84 changes: 78 additions & 6 deletions ExampleApp/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@
/* Begin PBXBuildFile section */
4211F22E2999730F00D13FD0 /* TextInputField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4211F22D2999730F00D13FD0 /* TextInputField.swift */; };
426A30E529E81D5A00C5FB02 /* MyRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 426A30E429E81D5A00C5FB02 /* MyRule.swift */; };
426CF63829850D1A00012FBE /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 426CF63729850D1A00012FBE /* ExampleApp.swift */; };
426CF63A29850D1A00012FBE /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 426CF63929850D1A00012FBE /* ContentView.swift */; };
426CF63C29850D1B00012FBE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 426CF63B29850D1B00012FBE /* Assets.xcassets */; };
426CF63F29850D1B00012FBE /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 426CF63E29850D1B00012FBE /* Preview Assets.xcassets */; };
426CF64929850DD400012FBE /* FormView in Frameworks */ = {isa = PBXBuildFile; productRef = 426CF64829850DD400012FBE /* FormView */; };
7392F4562CF76C8900331B40 /* HostingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F4552CF76C8900331B40 /* HostingController.swift */; };
7392F45A2CF76D7600331B40 /* StartFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F4592CF76D7500331B40 /* StartFactory.swift */; };
7392F45C2CF76FFB00331B40 /* StartCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F45B2CF76FFA00331B40 /* StartCoordinator.swift */; };
7392F45E2CF7701B00331B40 /* StartController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F45D2CF7701A00331B40 /* StartController.swift */; };
7392F4602CF7709D00331B40 /* StartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F45F2CF7709D00331B40 /* StartView.swift */; };
7392F4632CF7710900331B40 /* StartViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F4622CF7710800331B40 /* StartViewModel.swift */; };
7392F4652CF7717E00331B40 /* ContentFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F4642CF7717D00331B40 /* ContentFactory.swift */; };
7392F4692CF771AB00331B40 /* ContentCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F4682CF771AB00331B40 /* ContentCoordinator.swift */; };
7392F46B2CF771C900331B40 /* ContentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7392F46A2CF771C900331B40 /* ContentController.swift */; };
739E30032CF4A1AF009B795F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739E30022CF4A1AB009B795F /* AppDelegate.swift */; };
739E30052CF4A1CF009B795F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739E30042CF4A1CE009B795F /* SceneDelegate.swift */; };
E1DB5A1F2A73BFCF0024C47A /* ContentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1DB5A1E2A73BFCF0024C47A /* ContentViewModel.swift */; };
E1E8FCDB2A52B8CD0099A852 /* SecureInputField.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E8FCDA2A52B8CD0099A852 /* SecureInputField.swift */; };
/* End PBXBuildFile section */
Expand All @@ -22,12 +32,22 @@
4211F22D2999730F00D13FD0 /* TextInputField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextInputField.swift; sourceTree = "<group>"; };
426A30E429E81D5A00C5FB02 /* MyRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyRule.swift; sourceTree = "<group>"; };
426CF63429850D1A00012FBE /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
426CF63729850D1A00012FBE /* ExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleApp.swift; sourceTree = "<group>"; };
426CF63929850D1A00012FBE /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
426CF63B29850D1B00012FBE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
426CF63E29850D1B00012FBE /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
426CF64629850D9F00012FBE /* FormView */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FormView; path = ..; sourceTree = "<group>"; };
426CF64C29903DBC00012FBE /* Example-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "Example-Info.plist"; sourceTree = "<group>"; };
7392F4552CF76C8900331B40 /* HostingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HostingController.swift; sourceTree = "<group>"; };
7392F4592CF76D7500331B40 /* StartFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartFactory.swift; sourceTree = "<group>"; };
7392F45B2CF76FFA00331B40 /* StartCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartCoordinator.swift; sourceTree = "<group>"; };
7392F45D2CF7701A00331B40 /* StartController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartController.swift; sourceTree = "<group>"; };
7392F45F2CF7709D00331B40 /* StartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartView.swift; sourceTree = "<group>"; };
7392F4622CF7710800331B40 /* StartViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartViewModel.swift; sourceTree = "<group>"; };
7392F4642CF7717D00331B40 /* ContentFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentFactory.swift; sourceTree = "<group>"; };
7392F4682CF771AB00331B40 /* ContentCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentCoordinator.swift; sourceTree = "<group>"; };
7392F46A2CF771C900331B40 /* ContentController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentController.swift; sourceTree = "<group>"; };
739E30022CF4A1AB009B795F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
739E30042CF4A1CE009B795F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
E1DB5A1E2A73BFCF0024C47A /* ContentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentViewModel.swift; sourceTree = "<group>"; };
E1E8FCDA2A52B8CD0099A852 /* SecureInputField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecureInputField.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -66,10 +86,11 @@
426CF63629850D1A00012FBE /* ExampleApp */ = {
isa = PBXGroup;
children = (
426CF63729850D1A00012FBE /* ExampleApp.swift */,
426CF63929850D1A00012FBE /* ContentView.swift */,
E1DB5A1E2A73BFCF0024C47A /* ContentViewModel.swift */,
739E30022CF4A1AB009B795F /* AppDelegate.swift */,
739E30042CF4A1CE009B795F /* SceneDelegate.swift */,
426A30E429E81D5A00C5FB02 /* MyRule.swift */,
7392F4542CF76C7400331B40 /* Base */,
7392F4572CF76CB500331B40 /* UI */,
E1E8FCDC2A52C61D0099A852 /* InputFields */,
426CF63B29850D1B00012FBE /* Assets.xcassets */,
426CF63D29850D1B00012FBE /* Preview Content */,
Expand Down Expand Up @@ -100,6 +121,47 @@
name = Frameworks;
sourceTree = "<group>";
};
7392F4542CF76C7400331B40 /* Base */ = {
isa = PBXGroup;
children = (
7392F4552CF76C8900331B40 /* HostingController.swift */,
);
path = Base;
sourceTree = "<group>";
};
7392F4572CF76CB500331B40 /* UI */ = {
isa = PBXGroup;
children = (
7392F4612CF770E100331B40 /* ContentScreen */,
7392F4582CF76D6300331B40 /* StartScreen */,
);
path = UI;
sourceTree = "<group>";
};
7392F4582CF76D6300331B40 /* StartScreen */ = {
isa = PBXGroup;
children = (
7392F4592CF76D7500331B40 /* StartFactory.swift */,
7392F4622CF7710800331B40 /* StartViewModel.swift */,
7392F45B2CF76FFA00331B40 /* StartCoordinator.swift */,
7392F45D2CF7701A00331B40 /* StartController.swift */,
7392F45F2CF7709D00331B40 /* StartView.swift */,
);
path = StartScreen;
sourceTree = "<group>";
};
7392F4612CF770E100331B40 /* ContentScreen */ = {
isa = PBXGroup;
children = (
E1DB5A1E2A73BFCF0024C47A /* ContentViewModel.swift */,
7392F4642CF7717D00331B40 /* ContentFactory.swift */,
426CF63929850D1A00012FBE /* ContentView.swift */,
7392F46A2CF771C900331B40 /* ContentController.swift */,
7392F4682CF771AB00331B40 /* ContentCoordinator.swift */,
);
path = ContentScreen;
sourceTree = "<group>";
};
E1E8FCDC2A52C61D0099A852 /* InputFields */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -206,11 +268,21 @@
buildActionMask = 2147483647;
files = (
4211F22E2999730F00D13FD0 /* TextInputField.swift in Sources */,
7392F46B2CF771C900331B40 /* ContentController.swift in Sources */,
E1E8FCDB2A52B8CD0099A852 /* SecureInputField.swift in Sources */,
7392F4692CF771AB00331B40 /* ContentCoordinator.swift in Sources */,
7392F45E2CF7701B00331B40 /* StartController.swift in Sources */,
E1DB5A1F2A73BFCF0024C47A /* ContentViewModel.swift in Sources */,
7392F45C2CF76FFB00331B40 /* StartCoordinator.swift in Sources */,
7392F4602CF7709D00331B40 /* StartView.swift in Sources */,
7392F45A2CF76D7600331B40 /* StartFactory.swift in Sources */,
7392F4652CF7717E00331B40 /* ContentFactory.swift in Sources */,
7392F4632CF7710900331B40 /* StartViewModel.swift in Sources */,
426A30E529E81D5A00C5FB02 /* MyRule.swift in Sources */,
739E30032CF4A1AF009B795F /* AppDelegate.swift in Sources */,
426CF63A29850D1A00012FBE /* ContentView.swift in Sources */,
426CF63829850D1A00012FBE /* ExampleApp.swift in Sources */,
7392F4562CF76C8900331B40 /* HostingController.swift in Sources */,
739E30052CF4A1CF009B795F /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
20 changes: 20 additions & 0 deletions ExampleApp/ExampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AppDelegate.swift
// Example
//
// Created by Victor Kostin on 25.11.2024.
//

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

return true
}
}

29 changes: 29 additions & 0 deletions ExampleApp/ExampleApp/Base/HostingController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// HostingController.swift
// Example
//
// Created by Victor Kostin on 27.11.2024.
//

import SwiftUI
import UIKit

class HostingController<T: View>: UIHostingController<T> {
override init(rootView: T) {
super.init(rootView: rootView)
}

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .clear
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

@available(*, unavailable) @MainActor dynamic required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
17 changes: 0 additions & 17 deletions ExampleApp/ExampleApp/ExampleApp.swift

This file was deleted.

30 changes: 30 additions & 0 deletions ExampleApp/ExampleApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SceneDelegate.swift
// Example
//
// Created by Victor Kostin on 25.11.2024.
//

import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?

func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = (scene as? UIWindowScene) else {
return
}

window = UIWindow(windowScene: windowScene)
window?.windowScene = windowScene
window?.makeKeyAndVisible()

let rootViewController = StartFactory.createStartController()

window?.rootViewController = rootViewController
}
}
19 changes: 19 additions & 0 deletions ExampleApp/ExampleApp/UI/ContentScreen/ContentController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// ContentController.swift
// Example
//
// Created by Victor Kostin on 27.11.2024.
//

import SwiftUI

class ContentController: HostingController<ContentView> {
init(viewModel: ContentViewModel) {
super.init(rootView: ContentView(viewModel: viewModel))
print("init ContentController")
}

deinit {
print("deinit ContentController")
}
}
16 changes: 16 additions & 0 deletions ExampleApp/ExampleApp/UI/ContentScreen/ContentCoordinator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ContentCoordinator.swift
// Example
//
// Created by Victor Kostin on 27.11.2024.
//

import UIKit

class ContentCoordinator {
weak var router: UIViewController?

func pop() {
router?.navigationController?.popViewController(animated: true)
}
}
20 changes: 20 additions & 0 deletions ExampleApp/ExampleApp/UI/ContentScreen/ContentFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// ContentFactory.swift
// Example
//
// Created by Victor Kostin on 27.11.2024.
//

import UIKit

enum ContentFactory {
static func createContentController() -> UIViewController {
let coordinator = ContentCoordinator()
let viewModel = ContentViewModel(coordinator: coordinator)
let controller = ContentController(viewModel: viewModel)

coordinator.router = controller

return controller
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ struct ContentView: View {

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(viewModel: ContentViewModel())
ContentView(viewModel: ContentViewModel(coordinator: ContentCoordinator()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ class ContentViewModel: ObservableObject {
@Published var age: String = ""
@Published var pass: String = ""
@Published var confirmPass: String = ""

private let coordinator: ContentCoordinator

init(coordinator: ContentCoordinator) {
self.coordinator = coordinator
print("init ContentViewModel")
}

deinit {
print("deinit ContentViewModel")
}
}
14 changes: 14 additions & 0 deletions ExampleApp/ExampleApp/UI/StartScreen/StartController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// StartController.swift
// Example
//
// Created by Victor Kostin on 27.11.2024.
//

import UIKit

class StartController: HostingController<StartView> {
init(viewModel: StartViewModel) {
super.init(rootView: StartView(viewModel: viewModel))
}
}
17 changes: 17 additions & 0 deletions ExampleApp/ExampleApp/UI/StartScreen/StartCoordinator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// StartCoordinator.swift
// Example
//
// Created by Victor Kostin on 27.11.2024.
//

import UIKit

class StartCoordinator {
weak var router: UIViewController?

func push() {
let controller = ContentFactory.createContentController()
router?.navigationController?.pushViewController(controller, animated: true)
}
}
20 changes: 20 additions & 0 deletions ExampleApp/ExampleApp/UI/StartScreen/StartFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// StartFactory.swift
// Example
//
// Created by Victor Kostin on 27.11.2024.
//

import UIKit

enum StartFactory {
static func createStartController() -> UINavigationController {
let coordinator = StartCoordinator()
let viewModel = StartViewModel(coordinator: coordinator)
let controller = StartController(viewModel: viewModel)

coordinator.router = controller

return UINavigationController(rootViewController: controller)
}
}
Loading

0 comments on commit 47a0d6e

Please sign in to comment.