Skip to content

Commit 5036032

Browse files
committed
Clean code and add marks
1 parent 403f0ca commit 5036032

File tree

6 files changed

+42
-21
lines changed

6 files changed

+42
-21
lines changed

QRScanner/Source/Assembly/Assembler.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,15 @@ import UIKit
1010
class Assembler {
1111
func createCaptureModule(router: Router) -> UIViewController {
1212
let view = CaptureViewController()
13-
let presenter = CapturePresenter()
14-
13+
let presenter = CapturePresenter(view: view, router: router)
1514
view.presenter = presenter
16-
presenter.view = view
17-
presenter.router = router
1815

1916
return view
2017
}
2118

2219
func createWebViewModule(path: String, router: Router) -> UIViewController {
2320
let view = WebViewController()
24-
let presenter = WebViewPresenter()
25-
26-
presenter.view = view
27-
presenter.path = path
28-
presenter.router = router
21+
let presenter = WebViewPresenter(path: path, view: view, router: router)
2922
view.presenter = presenter
3023

3124
return view

QRScanner/Source/CaptureModule/Presenter/CapturePresenter.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ protocol CapturePresenterProtocol {
1212
}
1313

1414
class CapturePresenter: CapturePresenterProtocol {
15+
16+
//MARK: - Properties
1517

16-
var view: CaptureViewProtocol?
18+
weak var view: CaptureViewController?
1719
var router: Router?
1820

21+
//MARK: - Initializer
22+
23+
init(view: CaptureViewController, router: Router) {
24+
self.view = view
25+
self.router = router
26+
}
27+
28+
//MARK: - Methods
29+
1930
func catchCode(_ string: String) {
2031
router?.showWebView(path: string)
2132
}

QRScanner/Source/CaptureModule/View/CaptureViewController.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
import UIKit
99
import AVFoundation
1010

11-
protocol CaptureViewProtocol {
11+
class CaptureViewController: UIViewController {
1212

13-
}
14-
15-
class CaptureViewController: UIViewController, CaptureViewProtocol {
13+
//MARK: - Properties
1614

1715
var presenter: CapturePresenterProtocol?
1816
private var session = AVCaptureSession()
@@ -24,6 +22,8 @@ class CaptureViewController: UIViewController, CaptureViewProtocol {
2422
view.layer.cornerRadius = 6
2523
return view
2624
}()
25+
26+
//MARK: - Lifecycle
2727

2828
override func viewDidLoad() {
2929
super.viewDidLoad()
@@ -39,6 +39,8 @@ class CaptureViewController: UIViewController, CaptureViewProtocol {
3939
session.startRunning()
4040
}
4141

42+
//MARK: - Private methods
43+
4244
private func setupHierarchy() {
4345
view.addSubview(borderView)
4446
}
@@ -69,6 +71,8 @@ class CaptureViewController: UIViewController, CaptureViewProtocol {
6971
}
7072
}
7173

74+
//MARK: - Delegate methods
75+
7276
extension CaptureViewController: AVCaptureMetadataOutputObjectsDelegate {
7377
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
7478
borderView.frame = .zero

QRScanner/Source/Router/Router.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import UIKit
99

10-
protocol Router {
10+
protocol Router: AnyObject {
1111
func initialMainViewController()
1212
func showWebView(path: String)
1313
func popToRoot()

QRScanner/Source/WebViewModule/Presenter/WebViewPresenter.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,38 @@
77

88
import Foundation
99

10-
protocol WebViewPresenterProtocol {
10+
protocol WebViewPresenterProtocol: AnyObject {
1111
func getRequest()
1212
func showShared()
1313
func popTo()
1414
}
1515

1616
class WebViewPresenter: WebViewPresenterProtocol {
17-
var view: WebViewProtocol?
17+
18+
//MARK: - Properties
19+
20+
weak var view: WebViewProtocol?
1821
var router: Router?
19-
var path: String?
22+
var path: String
23+
24+
//MARK: - Initializer
25+
26+
init(path: String, view: WebViewProtocol, router: Router) {
27+
self.view = view
28+
self.router = router
29+
self.path = path
30+
}
31+
32+
//MARK: - Methods
2033

2134
func getRequest() {
22-
guard let url = URL(string: path ?? "") else { return }
35+
guard let url = URL(string: path) else { return }
2336
let request = URLRequest(url: url)
2437
view?.loadRequest(request: request)
2538
}
2639

2740
func showShared() {
28-
guard let url = URL(string: path ?? "") else { return }
41+
guard let url = URL(string: path) else { return }
2942
view?.presentShared(path: url)
3043
}
3144

QRScanner/Source/WebViewModule/View/WebViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import UIKit
99
import WebKit
1010

11-
protocol WebViewProtocol {
11+
protocol WebViewProtocol: AnyObject {
1212
func loadRequest(request: URLRequest)
1313
func presentShared(path: URL)
1414
}

0 commit comments

Comments
 (0)