-
iOS/WebView/Project - BaseViewController 모듈화#8Project/Swift+WebView 2023. 1. 11. 11:25
IOS/Xcode 14X Swift5.7.2 WKWebView 에서 작업 진행
모든 ViewController들이 상속 받을수 있는 BaseViewController를 만들어서 사용하자.
- 코드의 중복을 줄이기 위해서
- 코드의 통일성
- 유지보수 편의성
BaseViewController
import Foundation import UIKit class BaseViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. print("######### [BASE] ViewController - viewDidLoad") } } extension BaseViewController { func showAlert( title: String?, message: String?, confirmHandler: (() -> Void)? = nil, completion: (() -> Void)? = nil) { let alertView = UIAlertController(title: title, message: message, preferredStyle: .alert) let confirmAction = UIAlertAction(title: "Confirm", style: .default) { _ in if let handler = confirmHandler { handler() } } alertView.addAction(confirmAction) present(alertView, animated: true, completion: completion) } ... }
InitViewController
import Foundation import UIKit class InitViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. ... title = "InitViewController" print("######### Init ViewController - viewDidLoad") } }
MainViewController
import Foundation import UIKit class MainViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. print("######### Main ViewController - viewDidLoad") } }
참조
https://jintaewoo.tistory.com/56
https://didu-story.tistory.com/317
'Project > Swift+WebView' 카테고리의 다른 글
iOS/WebView/Project - Constants 및 Utils 분리#10 (0) 2023.01.13 iOS/WebView/Project - 싱글톤 패턴 AppInfo 추가#9 (0) 2023.01.12 iOS/WebView/Project - Splash 등록/설정#7 (0) 2023.01.11 iOS/WebView/Project - Assets 생성/등록#6 (0) 2023.01.10 iOS/WebView/Project - View 이동 테스트#5 (0) 2023.01.10