I've been doing .net core stuff lately and I have started again with Xcode (and rusty) this time with Xcode 9. I created a simple Objective-C project with the following steps (which I did before on older versions of Xcode:
- Deleted the default storyboard
- Deleted the launchscreen
- Modified the plist file for steps 1 and 2 above
- Created a new "Cocoa Touch Class" with subclass of UIViewController and XIB (named vcMain)
Modified the appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; UIViewController *mainView = [[UIViewController alloc] initWithNibName:@"vcMain" bundle:nil]; self.window.rootViewController = mainView; [self.window makeKeyAndVisible]; return YES; }
Modified the vcMain.h
- When I run it I get the error below (which I didn't get prior to linking the outlets and received actions in the XIB).
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key btnClient.' *** First throw call stack: ( 0 CoreFoundation 0x000000010475f12b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x0000000108cfaf41 objc_exception_throw + 48 2 CoreFoundation 0x000000010475f079 -[NSException raise] + 9 3 Foundation 0x00000001053b5a63 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292 4 UIKit 0x0000000106cf5117 -[UIViewController setValue:forKey:] + 87 5 UIKit 0x0000000106fe6c2d -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x00000001047023cd -[NSArray makeObjectsPerformSelector:] + 317 7 UIKit 0x0000000106fe55e3 -[UINib instantiateWithOwner:options:] + 1856 8 UIKit 0x0000000106cfc3ff -[UIViewController _loadViewFromNibNamed:bundle:] + 383 9 UIKit 0x0000000106cfcd2b -[UIViewController loadView] + 177 10 UIKit 0x0000000106cfd05c -[UIViewController loadViewIfRequired] + 195 11 UIKit 0x0000000106cfd8b9 -[UIViewController view] + 27 12 UIKit 0x0000000106bc87cf -[UIWindow addRootViewControllerViewIfPossible] + 122 13 UIKit 0x0000000106bc8ed7 -[UIWindow _setHidden:forced:] + 294 14 UIKit 0x0000000106bdbe54 -[UIWindow makeKeyAndVisible] + 42 15 [app name] 0x00000001040b7c8f -[AppDelegate application:didFinishLaunchingWithOptions:] + 639 16 UIKit 0x0000000106b4cbca -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 299 17 UIKit 0x0000000106b4e648 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4113 18 UIKit 0x0000000106b53aeb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720 19 UIKit 0x0000000106f1d6f8 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924 20 UIKit 0x00000001072f34c8 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153 21 UIKit 0x0000000106f1d2f1 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249 22 UIKit 0x0000000106f1db6b -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 696 23 UIKit 0x000000010789ba69 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262 24 UIKit 0x000000010789b922 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444 25 UIKit 0x00000001075789c8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221 26 UIKit 0x0000000107777b06 _performActionsWithDelayForTransitionContext + 100 27 UIKit 0x000000010757888b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231 28 UIKit 0x00000001072f2b25 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392 29 UIKit 0x0000000106b5236a -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523 30 UIKit 0x000000010712d605 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369 31 FrontBoardServices 0x000000011038dcc0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338 32 FrontBoardServices 0x00000001103967b5 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235 33 libdispatch.dylib 0x000000010a8a533d _dispatch_client_callout + 8 34 libdispatch.dylib 0x000000010a8aa9f3 _dispatch_block_invoke_direct + 592 35 FrontBoardServices 0x00000001103c2498 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24 36 FrontBoardServices 0x00000001103c214e -[FBSSerialQueue _performNext] + 464 37 FrontBoardServices 0x00000001103c26bd -[FBSSerialQueue _performNextFromRunLoopSource] + 45 38 CoreFoundation 0x0000000104702101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 39 CoreFoundation 0x00000001047a1f71 __CFRunLoopDoSource0 + 81 40 CoreFoundation 0x00000001046e6a19 __CFRunLoopDoSources0 + 185 41 CoreFoundation 0x00000001046e5fff __CFRunLoopRun + 1279 42 CoreFoundation 0x00000001046e5889 CFRunLoopRunSpecific + 409 43 GraphicsServices 0x000000010c9ae9c6 GSEventRunModal + 62 44 UIKit 0x0000000106b555d6 UIApplicationMain + 159 45 [app name] 0x00000001040b82bf main + 111 46 libdyld.dylib 0x000000010a921d81 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
I solved this by doing the changes on the AppDelegate.M
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
vcMain *mainView = [[vcMain alloc] initWithNibName:@"vcMain" bundle:nil];
/*
UIViewController *mainView = [[UIViewController alloc] initWithNibName:@"vcMain" bundle:nil];
*/
self.window.rootViewController = mainView;
[self.window makeKeyAndVisible];
return YES;
}