스토리 보드 안쓰고 코드로 View 만들때 appDelegete, sceneDelegate에 대해

2 답변 글타래를 보이고 있습니다
  • 글쓴이
    • Ky J
      참가자
      • 글작성 : 9
      • 답글작성 : 3

      // AppDelegate class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = TabBarViewController() self.window = window self.window?.makeKeyAndVisible() FirebaseApp.configure() return true }   // SceneDelegate 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 } let window = UIWindow(windowScene: windowScene) window.rootViewController = TabBarViewController() self.window = window self.window?.makeKeyAndVisible() }

      이런 코드를 독학중에 있습니다.. appDelegate의 window에 들어가는 VC와 SceneDelegate의 window에 VC.. 

      appDelegate에서 VC를 초기화를 했는데 또 SceneDelegate에서 VC를 초기화 하는 이유가 궁금합니다..

      3일동안 appDelegate와 SceneDelegate에 대해 검색을 해봤는데 모르겠어서 질문 합니다..ㅠㅠㅠ (<멍청)

      appDelegate는 앱의 LifeCycle에 관여를 하는데 왜 window를 설정하는지 모르겠네요.. var window도 어디에 쓰이고 있길래 전역변수인지..

      답변 해주시면 감사하겠습니다.. 링크만 주셔도 감사하겠습니다! 

      • 이 게시글은 Ky J에 의해 2 years, 4 months 전에 수정됐습니다.
    • 오동나무
      참가자
      • 글작성 : 0
      • 답글작성 : 16

      sceneDelegate는 iOS 13.0 이후에 등장한 개념입니다. 원래 appDelegate가 하던 역할(UI의 생명주기를 관리)을 하게 되었습니다.

      즉, iOS 13 이후로는 UI의 생명주기를 sceneDelegate가 담당하기 때문에 sceneDelegate 내부에서도 VC를 초기화해주어야 합니다.

       

      • window와 scene에 대해서 추가로 학습하면 좋을 것 같아요 🙂
      • 이 답변은 오동나무에 의해 2 years, 4 months 전에 수정됐습니다.
    • pinkjuice66
      참가자
      • 글작성 : 0
      • 답글작성 : 3

      윗 분 말씀처럼 appDelegate와 sceneDelegate가 함께 쓰일때는(iOS13 이후의 옵션사항) 

      sceneDelegate에서 UIWindow 객체를 가지고, 관리하게 됩니다. 즉, 글 작성자 분의 현재 코드를 살펴보면

      appDelegate와 sceneDelegate 모두에서 window property를 가지고 있는데, 

      sceneDelegate에서만 window property를 가져야 하는 것입니다.

      새로운 프로젝트를 하나 만들어 보시면  defualt로 appDelegate가 아닌 sceneDelegate 에서만 UIWindow 객체를 가지는 것을 확인할 수 있습니다.

2 답변 글타래를 보이고 있습니다
  • 답변은 로그인 후 가능합니다.

logo landscape small

사업자번호 : 743-81-02195
통신판매업 신고번호 : 제 2022-충북청주-1278 호
고객센터 : 카카오톡채널 @yagom