[Xcode] SceneDelegate 삭제하기
안녕하세요. 반해원입니다.
새 프로젝트 만들 때마다 찾아보는 내용인데용.
매번 검색해보기 귀찮아서 정리하는 글입니다. 🥲
AppDelegate.swift 만 필요하고 SceneDelegate.swift 는 사용하지 않는다면 아래와 같이 처리해 주면 됩니다.
실제로 SceneDelegate 를 언제 쓰게 될진 모르겠지만...... 언젠가는 쓰겠지요??
1️⃣ SceneDelegate.swift 파일 삭제
먼저 프로젝트를 새로 생성하면 아래와 같이 기본으로 파일들이 생성될 텐데 SceneDelegate 파일을 삭제해 줍니다.
그리고 실행해 보면 아래와 같은 경고 메시지들이 나온다.
[SceneConfiguration] Info.plist configuration "(no name)" for UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key,
but could not load class with name "TempApp.SceneDelegate".
[SceneConfiguration] Info.plist configuration "Default Configuration" for UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key,
but could not load class with name "TempApp.SceneDelegate".
[WindowScene] There is no scene delegate set. A scene delegate class must be specified to use a main storyboard file.
Info.plist 설정을 건드려줘야 한다는 거 같네요.
2️⃣ Application Scene Manifest 삭제
Info.plist 로 이동해서 Application Scene Manifest 항목을 지워줍니다.
그리고 다시 실행을 해보면 또 아래와 같은 메시지가 나오네요.
[SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "Default Configuration")
흠 어딘가에 Default Configuration 이라는 이름의 UIScene configuration dictionary 가 있나 봅니다.
AppDelegate.swift 에 UISceneSession Lifecycle 부분이 남아있었네요.
3️⃣ AppDelegate 의 UISceneSession Lifecycle 부분 삭제
AppDelegate.swift 로 이동해서 UISceneSession Lifecycle 메소드 2개를 삭제해 줍니다.
해치웠나...? 싶지만 아직입니다.
[Application] The app delegate must implement the window property if it wants to use a main storyboard file.
window 프로퍼티가 꼬옥 필요한데 없다네요..
아까 지운 SceneDelegate.swift 를 다시 보니 window 프로퍼티가 있었네요. 얘를 AppDelegate.swift 에 추가해 줍시다.
4️⃣ AppDelegate 에 window 프로퍼티 추가
아래와 같이 한 줄만 추가해 주면 됩니다.
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? // 추가
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
}
그리고 실행해 보면 이제 진짜 아무 경고 메시지 없이 Main 스토리보드가 실행되는 것을 볼 수 있습니다.
참고해서 프로젝트를 시작해 봅시다. 🧚🏻