[swift] 스토리보드 삭제하고 View 파일 바로 표시하는 방법

chosh·2023년 5월 12일
0
  1. Storyboard 파일로 앱을 생성하면 storyboard 파일이 자동으로 생성 된다

  2. storyboard 파일을 삭제한다

  3. navagator 에 제일 상단에 있는 프로젝트 클릭 -> Targets에 있는 프로젝트 클릭 -> info 탭 클릭 -> custom iOS Targets Properties -> Main storyboard file base name 을 클릭 후 커멘드 백스페이스를 눌러서 삭제

  4. navagator 에 제일 상단에 있는 프로젝트 클릭 -> Targets에 있는 프로젝트 클릭 -> info 탭 클릭 -> custom iOS Targets Properties -> Application Scene Manifest -> Scene Configuration -> Application Session Role -> Item 0 -> Storyboard Name을 클릭후 커맨드 백스페이스를 눌러서 삭제

  5. SceneDelegate.swift 파일 수정

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
	guard let windowScene = (scene as? UIWindowScene) else { return }
        
	let vc = ViewController() // 처음 표시될 뷰컨 클래스를 불러준다
        
	let window = UIWindow(windowScene: windowScene)
	window.rootViewController = vc
	window.makeKeyAndVisible()
	self.window = window
}
  1. scene 함수에서 guard let 바인딩을 해서 옵셔널 값을 벗겨준다
  2. 첫 화면으로 띄우고 싶은 뷰컨트롤러 이름을 vc라는 상수에 선언 해준다
  3. window에 대한 설정을 해준다.

참고자료

Build FULL iOS App in Swift (Rick & Morty | 2023) – Part 1

profile
제가 참고하기 위해 만든 블로그라 글을 편하게 작성했습니다. 틀린거 있다면 댓글 부탁드립니다.

0개의 댓글