반응형
목표: ViewController.swift, Main.storyboard 파일을 직접 사용하진 않을 것
UIKit
UIKit란? 화면을 구성하는 것들을 해줄 수 있는 라이브러리 (폰트, 라벨 등등)
처음에 기본이 되는 UIViewController 삭제함
그리고 새로 .swift 파일 생성 후 ViewController 선언!
import Foundation
import UIKit
class RootViewController: UIViewController {
}
UIViewController을 상속함으로써 UIViewController 역할을 할 수 있게 하자
·
·
·
LifeCycle(생성자) 선언
class RootViewController: UIViewController {
// MARK: Life Cycle functions
override func viewDidLoad() {
super.viewDidLoad()
}
}
View가 load 되었을 때 이 코드부터 실행하게 된다
하지만, 이 파일이 사용되려면 SceneDelegate 바꾸어야 함
·
·
·
새로 생성한 ViewController 사용하기 위해 SceneDelegate 편집
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: scene)
window?.rootViewController = RootViewController()
window?.makeKeyAndVisible()
}
window 인스턴스 기본으로는 nil 값이지만, 새롭게 인스턴스 생성하고
window의 rootViewController를 위에서 생성한 RootViewController로 설정!
makeKeyAndVisible로 해당 window를 보여주고, key window로 지정하면 RootViewController()의 내용물들이 나옴!!
반응형
'멀고도 험난한 개발 일지' 카테고리의 다른 글
UIKit_유투브_신동규 - #3 아무곳이나 클릭했을때 키보드 숨기는 법 (0) | 2022.07.18 |
---|---|
UIKit_유투브_신동규 - #2 Pro처럼 UI 디자인하기 (0) | 2022.07.10 |
이런저런_구글링_2 - Alamofire, 얼탱이 없는 Moya.. (0) | 2022.06.23 |
이런저런_구글링_1 - Date to String, Design Pattern, Voice Recorder, Post Method (0) | 2022.06.11 |
BeyondUI - 1주차 (HTTP, REST, URLSession, Codable, JSONDecoder ...) (0) | 2022.06.05 |