Error: App windows expected to have root view controller at app launch


I’m doing the first task of this chapter where you draw a red rectangle over the white screen. I’ve checked the code many times and even compared it to the source that you can download from Big Nerd. Every time I keep getting the runtime error pasted below. Any help much appreciated. I created the app as a “Single View Application”, by the way.

2017-04-16 11:52:49.385 Hypnosister[83668:10574734] *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/
2017-04-16 11:52:49.388 Hypnosister[83668:10574734] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Application windows are expected to have a root view controller at the end of application launch’
*** First throw call stack:
0 CoreFoundation 0x0000000107e9eb0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000105a3b141 objc_exception_throw + 48
2 CoreFoundation 0x0000000107ea2cf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00000001055d53b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x0000000105f0bbe6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 3343
5 UIKit 0x0000000105f08793 -[UIApplication workspaceDidEndTransaction:] + 182
6 FrontBoardServices 0x00000001095ae5f6 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
7 FrontBoardServices 0x00000001095ae46d -[FBSSerialQueue _performNext] + 186
8 FrontBoardServices 0x00000001095ae7f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
9 CoreFoundation 0x0000000107e44c01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
10 CoreFoundation 0x0000000107e2a0cf __CFRunLoopDoSources0 + 527
11 CoreFoundation 0x0000000107e295ff __CFRunLoopRun + 911
12 CoreFoundation 0x0000000107e29016 CFRunLoopRunSpecific + 406
13 UIKit 0x0000000105f0702f -[UIApplication _run] + 468
14 UIKit 0x0000000105f0d0d4 UIApplicationMain + 159
15 Hypnosister 0x000000010546d9cf main + 111
16 libdyld.dylib 0x0000000108e3e65d start + 1
17 ??? 0x0000000000000001 0x0 + 1
libc++abi.dylib: terminating with uncaught exception of type NSException


Looks like Xcode you are using is not compatible with the book you are using. It used to be okay not having a root view controller, and you would only get a warning if you did not have one.

When the AppDelegate object receives the application-finished-launching notification, you will need to explicitly set the rootViewController property of the window object.


Thank you! I thought that this might be the case as I am using this older book against the current Xcode. This is helpful.


Hi Rapdevpro
I do not know if it’s OK now, but It’s easy to crack it.As it said "reason: ‘Application windows are expected to have a root view controller at the end of application launch’"
I think you should do as below:
self.window.rootViewController=[[UIViewController alloc] init];

at- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions.