Fixing the Auto Complete Tutorial for iOS: How To Auto Complete With Custom Values

There's a great tutorial on RayWenderlich.com called "Auto Complete Tutorial for iOS: How To Auto Complete With Custom Values". However, as of Feb. 24th, 2016, the code as provided will not run. This is expected since the tutorial was written in February 10, 2010, but it's still useful so I thought I would fix it. You will see this error when you attempt to run it:

Warning: Error creating LLDB target at path '/Users/rommelrico/Library/Developer/Xcode/DerivedData/WebViewDemo-aqavlodtqkodavbfoillhdvztuuh/Build/Products/Debug-iphonesimulator/WebViewDemo.app'- using an empty LLDB target which can cause slow memory reads from remote devices.  
2016-02-24 08:26:14.678 WebViewDemo[6221:4400821] *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UIApplication.m:3315  
2016-02-24 08:26:14.681 WebViewDemo[6221:4400821] *** 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                      0x02168a14 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01c29e02 objc_exception_throw + 50
    2   CoreFoundation                      0x021688aa +[NSException raise:format:arguments:] + 138
    3   Foundation                          0x001acd26 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118
    4   UIKit                               0x005514aa -[UIApplication _runWithMainScene:transitionContext:completion:] + 3993
    5   UIKit                               0x00575ee5 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3218 + 68
    6   UIKit                               0x0054d966 -[UIApplication workspaceDidEndTransaction:] + 163
    7   FrontBoardServices                  0x038ffc76 __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
    8   FrontBoardServices                  0x038ff74d __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
    9   FrontBoardServices                  0x0391d173 -[FBSSerialQueue _performNext] + 184
    10  FrontBoardServices                  0x0391d5aa -[FBSSerialQueue _performNextFromRunLoopSource] + 52
    11  FrontBoardServices                  0x0391c8a6 FBSSerialQueueRunLoopSourceHandler + 33
    12  CoreFoundation                      0x020826ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    13  CoreFoundation                      0x0207838b __CFRunLoopDoSources0 + 523
    14  CoreFoundation                      0x020777a8 __CFRunLoopRun + 1032
    15  CoreFoundation                      0x020770e6 CFRunLoopRunSpecific + 470
    16  CoreFoundation                      0x02076efb CFRunLoopRunInMode + 123
    17  UIKit                               0x0054d206 -[UIApplication _run] + 540
    18  UIKit                               0x00552bfa UIApplicationMain + 160
    19  WebViewDemo                         0x00064b49 main + 121
    20  libdyld.dylib                       0x032e5a21 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException  
(lldb) 

So, how do we fix it?

We need to make two small changes. First, let's look at the error: "Application windows are expected to have a root view controller at the end of application launch". Prior to iOS 5, you did not need a root view controller. Most likely, Mr. Wenderlich based his code off of those old code samples. We can easily fix this by going to WebViewDemoAppDelegate. This is the apps starting App Delegate and runs "applicationDidFinishLaunching".

In WebViewDemoAppDelegate.m, change:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
  [window addSubview: navController.view];
  [window makeKeyAndVisible];
}

to

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
  [self.window setRootViewController:navController];
  [window makeKeyAndVisible];
}

All this does is manually sets the root view controller for the app to the UINavigationController.

Another minor fix

Starting in iOS 9.0 and OS X 10.11, a new feature call ATS (App Transport Security) is enabled by default. It basically requires that apps use HTTPS instead of HTTP for communication between the user and the app. We can deal with this by disabling it, but since this is a Web View Demo, I thought an appropriate fix is just to make all calls with https.

The error:

2016-02-24 08:40:10.113 WebViewDemo[6367:4476798] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.  

In WebViewController.m, change:
NSString *fullUrl = [[NSString alloc] initWithFormat:@"http://%@", self.url];

to:
NSString *fullUrl = [[NSString alloc] initWithFormat:@"https://%@", self.url];

That's it!

After doing all that, your code should work as specified in the tutorial.

Imgur

Imgur