Udemy의 The Swift Arcade Professional iOS 강의를 듣고 정리한 글입니다.
storyboard는 아직 보편화되지 않았고, 협업할 때 불편함이 있다. 따라서 전문적인 iOS 개발을 위해서는 스토리보드 없이 코드로만 개발하는 능력이 필요하다.
SceneDelegate, Main.storyboard 파일 제거
command + shift + f
후 main 검색INFOPLIST_KEY_UIMainStoryboardFile = Main
값 제거Application Scene Manifest
key 통째로 제거command + shift + j
: 현재 작업 중인 파일로 이동하는 단축키
AppDelegate 클래스 내 모든 내용을 지워준다.
AppDelegate 클래스 안에 아래 코드를 추가한다.
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.backgroundColor = .white
window?.rootViewController = ViewController()
return true
}
AppDelegate.swift 소스파일은 두 가지 역할을 한다.
app delegate는 AppDelegate 클래스의 인스턴스로, app delegate는 우리 앱의 객체이다. (app delegate와 AppDelegate는 다른 놈들이다!)
app delegate는 앱의 상태에 따라 응답하는 콘텐츠가 그려지는 창(window)을 만든다.
즉, AppDelegate.swift가 있으므로 AppDelegate 클래스가 만들어지고, 이 AppDelegate 클래스의 인스턴스인 app delegate가 우리 앱의 내용이 그려질 창(window)를 만드는 것이다.
이 작업은 UIApplicationMain 속성에 의해 수행되며, 이 속성은파일의 맨 위에 나타난다. (Xcode 12 이후에는 @main
으로 대체되었다.) UIApplicationMain 속성을 사용하는 것은 UIApplicationMain 함수를 호출하고 AppDelegate 클래스의 이름을 delegate 클래스에 전달하는 것과 동일하다. 이에 대한 응답으로 시스템은 응용프로그램 객체(application object)를 생성한다. 응용프로그램 객체는 app의 life cycle을 담당한다.
또한 시스템은 AppDelegate 클래스의 인스턴스를 생성하고 이를 응용프로그램 객체에 할당한다.
마지막으로, 시스템은 앱을 실행한다.
✔️ 참고링크